Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ Lua ➜ Saving timers

Saving timers

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


Posted by Zimmy   (31 posts)  Bio
Date Mon 28 Oct 2019 11:43 PM (UTC)
Message
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.)
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #1 on Tue 29 Oct 2019 08:19 AM (UTC)
Message

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).


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Zimmy   (31 posts)  Bio
Date Reply #2 on Tue 29 Oct 2019 12:49 PM (UTC)
Message
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?
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #3 on Wed 30 Oct 2019 05:50 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #4 on Tue 03 Nov 2020 09:37 PM (UTC)
Message

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


- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


16,504 views.

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

Go to topic:           Search the forum


[Go to top] top

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