Difference between revisions of "Os.startTimer"
From ComputerCraft Wiki
Bomb Bloke (Talk | contribs) (Another example.) |
Bomb Bloke (Talk | contribs) m |
||
Line 6: | Line 6: | ||
|returns={{type|number}} timerID | |returns={{type|number}} timerID | ||
|addon=ComputerCraft | |addon=ComputerCraft | ||
− | |desc=Adds a timer which will fire a single [[Timer_(event)|"timer" event]] after <var>time</var> seconds have passed. It also returns a number representing | + | |desc=Adds a timer which will fire a single [[Timer_(event)|"timer" event]] after <var>time</var> 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 [[os.pullEvent|pull it]]).<br><br> |
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 [[os.sleep|sleep()]] relies on timer events to function (as do other functions that can wait for a set period of time - eg [[rednet.receive|rednet.receive()]]), sleep(1.01) and sleep(1.05) would both wait for at least 1.05 seconds. | 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 [[os.sleep|sleep()]] relies on timer events to function (as do other functions that can wait for a set period of time - eg [[rednet.receive|rednet.receive()]]), sleep(1.01) and sleep(1.05) would both wait for at least 1.05 seconds. |
Latest revision as of 13:24, 17 December 2014
Function os.startTimer | |
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
Example | |
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 |