os.startTimer
From ComputerCraft Wiki
| Adds a timer which will fire a single "timer" event after time seconds have passed. It also returns a number representing the unique ID of the timer (which will likewise be included with said event, allowing you to identify it when you pull it). Fractions of a second are supported, but only down to a game tick, or 1/20th of a second (0.05s) - note that even a timer set for 0 seconds will not fire until at least a tick has passed. Likewise, given that sleep() relies on timer events to function (as do other functions that can wait for a set period of time - eg rednet.receive()), sleep(1.01) and sleep(1.05) would both wait for at least 1.05 seconds. | |
| Syntax | os.startTimer(number time) |
| Returns | number timerID |
| Part of | ComputerCraft |
| API | OS |
Examples
| Yields until 3 seconds have passed. | |
| Code |
local myTimer = os.startTimer(3)
while true do
local event, timerID = os.pullEvent("timer")
if timerID == myTimer then break end
end
|