Hello,
I have a question regarding timers. I want to make a timer that fires on the hour, every hour. For example, I want the timer to fire at:
9:00 am
10:00 am
11:00 am
etc.
I can't really use the every hourly interval method because if I start up the client at 8:30 am, I don't want the timer to fire at 9:30 am, I need it to fire at 9:00 am.
Any suggestions on how to do this?
You can probably do it the complicated way by making a script "on connect" that works out how many minutes to the next hour, then adds a timer that goes off in that many minutes (eg. 23 minutes). That timer calls another script that sets the hourly timer.
However, why not just add 24 one-hour timers, one for each hour of the day? There is no CPU overhead, they just tick away quietly in the background. If you don't want to add them all manually in the dialog box, just open an "immediate" scripting window (Ctrl+I) and enter this ...
World.addtimer "timer1", 0, 0, 0, "", 3, "myscript"
World.addtimer "timer2", 1, 0, 0, "", 3, "myscript"
World.addtimer "timer3", 2, 0, 0, "", 3, "myscript"
World.addtimer "timer4", 3, 0, 0, "", 3, "myscript"
... and so on up to ...
World.addtimer "timer24", 23, 0, 0, "", 3, "myscript"
Each timer calls the same script subroutine "myscript" that does whatever you want to have happen on the hour. Make sure the function "myscript" exists before adding the timers or the add will fail.
Thank you so much, in writing some new scripts I completely missed the simple solution of adding a timer for each hour. :) Thank you very much Nick. As long as there is no overhead for each timer, that is exactly the solution I'm looking for, thanks again. :)
Oh, just one more quick question. By using a flags value of 5, this enables and tells the timer to fire once. What if the person stays connected to the mud for more than 24 hours, and the timer needs to fire on that 25th hour? Do I simply change the flag value from 5 to 1 so that each timer persists?
I had a flag of 3 - this is from the web page on addtimer:
const eEnabled = 1 ' is timer enabled?
const eAtTime = 2 ' if not set, time is "every"
const eOneShot = 4 ' if set, timer only fires once
const eReplace = 1024 ' replace existing timer of same name
The flags are 1 - enabled, plus 2 - fire at a time (the description is a bit obscure). You don't want flag 4 (once) because then the timer won't work over 24 hours.
Thus you want 1 + 2 = 3.