Can NOT SetTimerOption for "second"

Posted by Jcl2016 on Mon 28 Nov 2016 03:12 AM — 8 posts, 31,798 views.

#0
No matter what I set to the "second" option, the timer will be triggered at 0 second.


SetTimerOption("xxx", "second", 9)
Note(GetTimerOption("xxx", "second"))  -- result is 0.
Australia Forum Administrator #1
I can't reproduce that. I got "9" printed.

Template:version
Please help us by advising the version of MUSHclient you are using. Use the Help menu -> About MUSHclient.


Does the timer exist? What scripting language are you using?
#2
Nick Gammon said:

I can't reproduce that. I got "9" printed.

(version)

Does the timer exist? What scripting language are you using?


Version 5.02. The scripting language is Lua.

The timer is definitely there,it is "at the time" timer.

( The "every interval" timer is correct. )
USA Global Moderator #3
I also can't reproduce this. Just for completeness, can you verify that copying/pasting this code exactly still prints 0 instead of 9?

AddTimer("xxx", 0, 0, 1.5, "", timer_flag.OneShot, "")
SetTimerOption("xxx", "second", 9)
Note(GetTimerOption("xxx", "second"))
Australia Forum Administrator #4
I can reproduce it with an "at" timer. There is definitely a bug there, introduced when the seconds field became a floating point (so you can have 0.1 seconds).

I suggest as a work-around that you delete and re-add the timer. Or use "addxml.lua" module: http://www.gammon.com.au/forum/?id=7123

For example:


require "addxml"
addxml.timer {  at_time = true,
                hour = 23, minute = 15, second = 16.8,
                send = "Timer fired!",
                send_to = sendto.output,
                enabled = true,
                name = "whatever",
              }


If you give a name to the timer it replaces another one of the same name (if any).

However perhaps you don't really want an "at" timer? I think this has gone unreported for so long because usually an "at" timer is for stuff like rotating your log files once a day, at midnight, and no-one cares if it is done at midnight or midnight + 5 seconds.

If you are trying to know when something happens in the near future (where 9 seconds would make a difference) like when a spell wears off, you are probably better off with an "every" timer, and make it "one-shot". A one-shot timer fires once and then deletes itself. This would be easier anyway because you probably know the interval, and using an "at" timer means you have to take the interval, add in the time right now, and get the time in the future when you want it to fire.
USA Global Moderator #5
Nick Gammon said:

I can reproduce it with an "at" timer.

Oh, is that what '"at the time" timer' meant. I totally missed that.
#6
Nick Gammon said:

I can reproduce it with an "at" timer. There is definitely a bug there, introduced when the seconds field became a floating point (so you can have 0.1 seconds).

I suggest as a work-around that you delete and re-add the timer. Or use "addxml.lua" module: http://www.gammon.com.au/forum/?id=7123


Thank you for your suggest, I will try it.

I really want the "at" timers.

An event will occur at a specific time. It's MUD server's time. I need to do something before the event and keep idle for a while. And then I need to do another thing after the specific time, no matter whether the event occurred or not.

For example, I need two "at" timers fire at 10:00:25 and 10:00:35 respectively. Unfortunately, the plugin will run on multiple machines, and the system time of each machine is not the same. So I need SetTimerOption to adjust the fire time dynamically.
As the bug you know, two timers were both be set to 10:00:00 and fired at the same time.
Australia Forum Administrator #7
Fixed in version 5.04.