OS

From ComputerCraft
Jump to: navigation, search
EventEventalarm
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
ExampleExampleSetting an alarm
Set's an alarm at 11 'o clock and tells the player to take the cake out of the oven.
Code
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!")
EventEventterminate
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
Part of CC:Tweaked
ExampleExampleWait for termination
Prints Nope! every time an event is fired that is not termination, at which point Goodbye is printed
Code
while true do
  local event = os.pullEventRaw()
  if event == 'terminate' then
    print("Goodbye")
    return
  else
    print("Nope!")
  end
end
EventEventtimer
Occurs when a previously set timer has elapsed.
Returns
  • timer : number unique timer number
Part of CC:Tweaked
See also os.setTimer
ExampleExampleUsing the Timer event
Sets a timer at 5 seconds, then waits for it to finish.
Code
local myTimer = os.startTimer(5)
local event, timerNumber
while timerNumber ~= myTimer do
  event, timerNumber = os.pullEvent("timer")
end
print("A timer has finished!")