Difference between revisions of "Alarm (event)"

From ComputerCraft Wiki
Jump to: navigation, search
(better coding habits)
m (Fixed the example (hopefully))
 
Line 1: Line 1:
 +
{{lowercase}}
 
{{Event
 
{{Event
 
|name=alarm
 
|name=alarm
 
|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]]() is initially called).
 
|examples=
 
|examples=
 
{{Example
 
{{Example
|desc=Sets the alarm for 1 (in-game) hour, then waits for the event to fire
+
|desc=Sets the alarm at 7.00 (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
+
|code= local alarmID = [[os.setAlarm]](7) -- Sets the Alarm at 7.00
 +
 
  while true do
 
  while true do
   local event, id = os.pullEvent("alarm") -- Waits for the alarm event
+
   local event, id = '''[[os.pullEvent]]("alarm")''' -- Waits for the alarm event
   if id == alarm then -- Checks to see if it's the alarm we created
+
 
 +
   if id == alarmID then -- Checks to see if it's the alarm we created
 
     print("The alarm has gone off!")
 
     print("The alarm has gone off!")
 
     break -- Get out of the loop
 
     break -- Get out of the loop

Latest revision as of 16:36, 10 April 2014



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 at 7.00 (in-game) hour, then waits for the event to fire.
Code
local alarmID = os.setAlarm(7) -- Sets the Alarm at 7.00

while true do
  local event, id = os.pullEvent("alarm") -- Waits for the alarm event
  
  if id == alarmID 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