Saving timers

Posted by Zimmy on Mon 28 Oct 2019 11:43 PM — 5 posts, 24,040 views.

#0
I'd like to know what the best way to save or preserve timers over plugin re-installs is. Should I write a function with GetTimers(), iterate through the results and use GetTimerInfo() for every attribute I need and store everything in a serialized table. Then I'd need to load the table on install and reconstruct all the timers from the table data. This is completely doable, I just want to know if there's an easier way.

I'm also curious what happens when mushclient is exited. Do the timers pause or will the time passed be subtracted from the timers when you open mushclient again? (I'd like the timers to keep track of real time, not just when I have the world open.)
Australia Forum Administrator #1

Timers are not paused when the client exits. Timers fire at two different possible places:

  • At a particular time of day
  • After X seconds (minutes/hours)

In the first case, the timer will still fire at that time of day. In the second case, the count-up will start again.

If you want a timer to mark a certain event, then you need to do that yourself. A bit would depend on whether the timer runs (so to speak) when you are not logged on.

If a certain event happens after X hours (logged on or not) then that is different to if the event happens after X hours, but only while you are logged on.

(I’d like the timers to keep track of real time, not just when I have the world open.)

The simplest thing then would be to have the timer set up to fire at a certain time of day (eg. 9 pm) then it will fire at 9 pm if you are logged on (and obviously not if you are not).

#2
Nick Gammon said:

The simplest thing then would be to have the timer set up to fire at a certain time of day (eg. 9 pm) then it will fire at 9 pm if you are logged on (and obviously not if you are not).


Sorry, I think I explained what I needed poorly. I have variables that are based on mud-side information that becomes irrelevant after a certain amount of time. I'm using the timers to reset these variables (back to unknown) after two hours. This means that if I exit mushclient and come back in five hours, I'd like all my variables to be reset.

Also, did I have the right idea with saving timers?
Australia Forum Administrator #3
Yes, you can iterate through the timers, but I think it is simpler in your case to "remember" (in a variable or file) when these events expire. eg.


an_hour_from_now = os.time() + 60 * 60

print (os.date ('%Y-%m-%d %H:%M', an_hour_from_now))


So if you restart the client you could find the time now, and if it is greater than the computed time of this event finishing, then consider the event over.
Australia Forum Administrator #4

See here for an example of preserving timers over reinstalls or being logged out.