6 posts
Posted 22 April 2012 - 02:05 PM
Is there a way to make a timer tick without using os.startTimer() that freezes the rest of the program?
For an example id like a timer to tick once a sec for a count down.
161 posts
Posted 22 April 2012 - 06:56 PM
So you want to freeze the program during the timeout time? Just use "os.sleep".
6 posts
Posted 22 April 2012 - 09:17 PM
im sorry, i ment doesnt freeze xD
113 posts
Posted 22 April 2012 - 09:19 PM
So, it counts down, but doesn't freeze? I don't know if that's possible. I sure can't do it.
161 posts
Posted 22 April 2012 - 10:08 PM
Wait, so you mean you don't want execution to stop, that is, you want to start the timer but keep doing other things while it's running? That's what "os.startTimer" is for. You can handle the timer as well as other input with "os.pullEvents".
1604 posts
Posted 23 April 2012 - 12:03 AM
If you want to use os.pullEvent() but don't want it to stop your program, you can queue a fake event:
local timer = os.startTimer(10)
while true do
os.queueEvent("fake")
local evt, arg = os.pullEvent()
if evt == "timer" and arg == timer then
do_something()
end
-- continue program
end