Difference between revisions of "Timer (event)"

From ComputerCraft Wiki
Jump to: navigation, search
(Created event page.)
 
m (May need more work)
Line 5: Line 5:
 
|desc=Fired when a timer completes.
 
|desc=Fired when a timer completes.
 
|return1=The timer's numerical representation value (returned when [[os.startTimer|os.startTimer()]] is initially called).
 
|return1=The timer's numerical representation value (returned when [[os.startTimer|os.startTimer()]] is initially called).
 +
}}
 +
{{Example
 +
|desc=This code will continuously start an internal timer and fire an event. If the event is not the timer, then it will break the loop
 +
|code= while true do<br/>  os.startTimer(1)<br/>  event = os.pullEvent()<br/>  if event == "timer" then <br/>    print("Too slow!")<br/>  else<br/>    print("Darn, you beat me!")<br/>    break<br/>  end<br/>end
 
}}
 
}}

Revision as of 12:40, 29 March 2013

This page needs some serious TLC, stat!
Please help us by cleaning it, fixing it up, or sparing it some love.
(Reason: A demonstration on the use and handling of this event would be beneficial. AfterLifeLochie 16:11, 30 November 2012 (MSK))



Grid Modem.png  Event timer
Fired when a timer completes.
Returned Object 1 The timer's numerical representation value (returned when os.startTimer() is initially called).


Grid paper.png  Example
This code will continuously start an internal timer and fire an event. If the event is not the timer, then it will break the loop
Code
while true do
os.startTimer(1)
event = os.pullEvent()
if event == "timer" then
print("Too slow!")
else
print("Darn, you beat me!")
break
end
end