OS

Eventalarm
Occurs when a previously set alarm is scheduled to go off.
Returns
  • alarm : number unique alarm number
Part of CC:Tweaked
See also os.setAlarm
ExampleSetting an alarm
Set's an alarm at 11 'o clock and tells the player to take the cake out of the oven.
Code
<nowiki>
local myAlarm = os.setAlarm(11)
local event, alarmNumber
while alarmNumber ~= myAlarm do
  event, alarmNumber = os.pullEvent("alarm")
end
print("The cake should be taken out of the oven! Watch out, it is hot!")
    </nowiki>
Eventterminate
Occurs when the user holds down Ctrl-T to terminate the running program. Note that this event is intercepted by os.pullEvent, which handles it by forcefully terminating the program. To handle it, use os.pullEventRaw (or coroutine.yield) instead.
Returns
    nil
Part of CC:Tweaked
ExampleWait for termination
Prints Nope! every time an event is fired that is not termination, at which point Goodbye is printed
Code
<nowiki>
while true do
  local event = os.pullEventRaw()
  if event == 'terminate' then
    print("Goodbye")
    return
  else
    print("Nope!")
  end
end
    </nowiki>
Eventtimer
Occurs when a previously set timer has elapsed.
Returns
  • timer : number unique timer number
Part of CC:Tweaked
See also os.setTimer
ExampleUsing the Timer event
Sets a timer at 5 seconds, then waits for it to finish.
Code
<nowiki>
local myTimer = os.startTimer(5)
local event, timerNumber
while timerNumber ~= myTimer do
  event, timerNumber = os.pullEvent("timer")
end
print("A timer has finished!")
    </nowiki>
This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.