Difference between revisions of "Os.startTimer"

From ComputerCraft Wiki
Jump to: navigation, search
(Improved example.)
Line 9: Line 9:
 
  |examples=
 
  |examples=
 
{{Example
 
{{Example
|desc=Yields until 3 seconds have passed
+
|desc=Yields until 3 seconds have passed.
|code=os.startTimer(3)<br>os.pullEvent(timer)
+
|code=local myTimer = os.startTimer(3)<br>while true do<br>  local event,timerID = os.pullEvent("timer")<br>  if timerID == myTimer then break end<br>end
 
}}
 
}}
 
}}
 
}}
  
 
[[Category:Lua_Core_Functions]]
 
[[Category:Lua_Core_Functions]]

Revision as of 01:51, 23 November 2013


Grid Redstone.png  Function os.startTimer
Adds a timer which will fire a "timer" event once after time seconds have passed. It returns an int which acts as a unique ID for the timer. Fractions of a second are supported, but only down to a game tick, or 1/20 of a second (0.05s). Times are rounded up to the next tick, so os.sleep(1.01) and os.sleep(1.05) both wait for 1.05 seconds.
Syntax os.startTimer(number time)
Returns number timerID
Part of ComputerCraft
API OS

Examples

Grid paper.png  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