Adding time to a timer

Post Reply
Nerrok
Posts: 1
Joined: Sat Jul 05, 2014 11:10 am

Adding time to a timer

Post by Nerrok »

I tried looking all over for the solution for this one, but no luck.

I want to add time to an existing timer. Let's say my MUD sends this line to me:

Wait 10 seconds.

I can make a tempTimer to track that and then give me an echo when the time's up. But then something like this happens on the MUD a few seconds later:

Wait an additional 5 seconds.

Is there a way to add that time to the tempTimer? Or is there a way to at least get the time remaining on the previous timer, add the new time to it, and then recreate the timer?

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: Adding time to a timer

Post by demonnic »

There's no direct way I know of to query a timer for its time, or to add time to do it. What I would recommend is using a stopWatch ( createStopWatch , startStopWatch , stopStopWatch , and resetStopWatch ) to keep track of the amount of time which has elapsed, killTimer to wipe out the timer currently running, and then create a new timer with the amount of time left over (original time - time on the stopWatch + the extra amount the server states), resetting the stop watch and starting it again so that if it happens again you can adjust once more.

To do this, you'll want to store the following information in a table somewhere, I think:

What you're trying to do (the send or the function you're running)
How long the total time to do the task is (for comparison and adjustment of the time)
timer ID
stopWatch ID


I don't know if this is just for one thing, or if you want to keep it generic for use by more than one task, but keep in mind what your goal is while writing it. I'm also not sure what your level of comfort is with these concepts, so if I've used strokes which are too broad to describe it, let me know and I'll break out the code editor =)

User avatar
SlySven
Posts: 1023
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: Adding time to a timer

Post by SlySven »

Just a quick note, the stopwatch functionality is not as much like a stopwatch as one might like (it can't actually be stopped and started like a real elapsed time measurement device!) I have a more real-life-like stop watch implementation in the (C++ code) works, which IMHO is a bit more elegant (though it also allows "adjusting" of the elapsed time amongst other things), but I'll make a note to see if it is possible to give the user a chance to find out more about existing timers.

I'll also have to check but I recall something about "offset" timers but without RTFMing, I don't know much about that particular topic though it does sound as if it might be relevant...

Post Reply