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

Making a timer tick

Started by iStone, 22 April 2012 - 12:05 PM
iStone #1
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.
Hawk777 #2
Posted 22 April 2012 - 06:56 PM
So you want to freeze the program during the timeout time? Just use "os.sleep".
iStone #3
Posted 22 April 2012 - 09:17 PM
im sorry, i ment doesnt freeze xD
EmTeaKay #4
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.
Hawk777 #5
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".
MysticT #6
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