Posted 01 September 2012 - 10:36 PM
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…
os.startTimer(time)
and then wait for a "timer" event.Just use:and then wait for a "timer" event.os.startTimer(time)
A quick look at the wiki would have answered this.
I just checked the wiki and it says that it makes a table to show when its done, I don't really know anything about tables, could I have an example of the code that detects when the timer is over? Or can I use a os.pullEvent?Just use:and then wait for a "timer" event.os.startTimer(time)
A quick look at the wiki would have answered this.
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
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: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