This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Ghozer's profile picture

[lua][question] restarting a specific timer

Started by Ghozer, 08 July 2012 - 10:11 PM
Ghozer #1
Posted 09 July 2012 - 12:11 AM
I have set an os.startTimer() running, and pulled it's ID out using timer = os.startTimer(timeout)

now I have the ID, is there a way of passing said ID to os.starTimer and re-starting the timer? (or stop it, and start a new one)
Lyqyd #2
Posted 09 July 2012 - 02:08 AM
You can always just start a new one with the same ID. The old timer event will still fire, but the variable will have something different in it now, so any comparisons checking to see which timer fired won't find the one you've changed until its latest timer start times out.
Ghozer #3
Posted 09 July 2012 - 04:40 PM
I don't want the old timer to fire, basically I have a menu system set up, and I want a timer that returns to the main menu if nothing happens for say, 2 minutes.. (120 secs)

as it is, an option is pressed, a timer is started, another option is pressed, it starts another timer, I did try setting timer = startTimer(120) and checking if 'timer' was true, but I don't know how to set a timer (or restart it) using the same ID (which is storred in the timer variable)
Lyqyd #4
Posted 09 July 2012 - 06:17 PM
Well, here's what I said above in code form, basically. To start a timer:


timeOutTimer = os.startTimer(120)

To check which timer fired:


e, p = os.pullEvent()
if e == timer then
--All timer events will end up here
    if p == timeOutTimer then
    --But only the latest timeOutTimer will end up here.
    end
end

You can't keep the old timer from firing, but you can act only on the correct one.
Ghozer #5
Posted 09 July 2012 - 07:31 PM
Seems to now be sorted… thanks…. :)/>/>