Difference between revisions of "Alarm (event)"

From ComputerCraft Wiki
Jump to: navigation, search
(Created event page.)
 
(Added example)
Line 5: Line 5:
 
|desc=Fired when an alarm has expired.
 
|desc=Fired when an alarm has expired.
 
|return1=The alarm's numerical representation value (returned when [[os.setAlarm|os.setAlarm()]] is initially called).
 
|return1=The alarm's numerical representation value (returned when [[os.setAlarm|os.setAlarm()]] is initially called).
 +
|examples=
 +
{{Example
 +
|desc=Sets the alarm for 1 (in-game) hour, then waits for the event to fire
 +
|code=local alarm = os.setAlarm(os.time()+01.00) -- Sets the Alarm for 1 hour after the current time<br>while true do<br> local  _, id = os.pullEvent("alarm") -- Waits for the alarm event<br>  if id == alarm then -- Checks to see if it's the alarm we created<br>    print("The alarm has gone off!")<br>    break -- Get out of the loop<br>  end<br>end
 +
}}
 
}}
 
}}

Revision as of 02:04, 13 April 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:13, 30 November 2012 (MSK))



Grid Modem.png  Event alarm
Fired when an alarm has expired.
Returned Object 1 The alarm's numerical representation value (returned when os.setAlarm() is initially called).

Examples

Grid paper.png  Example
Sets the alarm for 1 (in-game) hour, then waits for the event to fire
Code
local alarm = os.setAlarm(os.time()+01.00) -- Sets the Alarm for 1 hour after the current time
while true do
local _, id = os.pullEvent("alarm") -- Waits for the alarm event
if id == alarm then -- Checks to see if it's the alarm we created
print("The alarm has gone off!")
break -- Get out of the loop
end
end