Hi, I probably already know this but I forgot, but what is the code to use a timer, I'm pretty sure that the os API has one, but there might be others, I'm not sure...
[Question] Timer
Started by Matrixmage, Sep 01 2012 09:36 PM
5 replies to this topic
#1
Posted 01 September 2012 - 09:36 PM
#4
Posted 01 September 2012 - 10:11 PM
MysticT, on 01 September 2012 - 09:39 PM, said:
Just use:
A quick look at the wiki would have answered this.
os.startTimer(time)and then wait for a "timer" event.
A quick look at the wiki would have answered this.
#5
Posted 01 September 2012 - 10:15 PM
The table is just used as an identifier for the timer, you don't need to use it. Just wait for a "timer" event (using os.pullEvent) and then check if the argument of the event equals the table returned by os.startTimer.
Example:
Example:
local timer = os.startTimer(5) -- start a timer for 5 seconds
while true do
local evt, arg = os.pullEvent("timer") -- wait for a timer event
if arg == timer then -- check if the timer fired is the one started before
print("Time's up!")
break
end
end
#6
Posted 01 September 2012 - 10:19 PM
MysticT, on 01 September 2012 - 10:15 PM, said:
The table is just used as an identifier for the timer, you don't need to use it. Just wait for a "timer" event (using os.pullEvent) and then check if the argument of the event equals the table returned by os.startTimer.
Example:
Example:
local timer = os.startTimer(5) -- start a timer for 5 seconds
while true do
local evt, arg = os.pullEvent("timer") -- wait for a timer event
if arg == timer then -- check if the timer fired is the one started before
print("Time's up!")
break
end
end
Ok, thanks for the help!
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











