[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Timer to fire every hour, on the hour

Timer to fire every hour, on the hour

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Larken   (4 posts)  [Biography] bio
Date Sun 14 Apr 2002 05:51 AM (UTC)
Message
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?
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sun 14 Apr 2002 12:05 PM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Larken   (4 posts)  [Biography] bio
Date Reply #2 on Sun 14 Apr 2002 02:39 PM (UTC)
Message
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. :)
[Go to top] top

Posted by Larken   (4 posts)  [Biography] bio
Date Reply #3 on Sun 14 Apr 2002 02:54 PM (UTC)
Message
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?
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Sun 14 Apr 2002 09:36 PM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


12,051 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]