Difference between revisions of "Os.setAlarm"

From ComputerCraft Wiki
Jump to: navigation, search
(Created page with "{{lowercase}} {{Function |name=os.setAlarm |args=float time |api=os |returns=table alarmID |addon=ComputerCraft |desc=Adds an alarm which will fire ...")
 
(Use the example template instead of standard code blocks.)
 
(7 intermediate revisions by 4 users not shown)
Line 2: Line 2:
 
{{Function
 
{{Function
 
  |name=os.setAlarm
 
  |name=os.setAlarm
  |args=[[float (type)|float]] time
+
  |args={{type|number}} time
  |api=os
+
  |api=OS
  |returns=[[table]] alarmID
+
  |returns={{type|table}} alarmID
 
  |addon=ComputerCraft
 
  |addon=ComputerCraft
 
  |desc=Adds an alarm which will fire an "alarm" event at the specified Minecraft world time. The returned table acts as a unique ID for the alarm.
 
  |desc=Adds an alarm which will fire an "alarm" event at the specified Minecraft world time. The returned table acts as a unique ID for the alarm.
 
  |examples=
 
  |examples=
 +
{{Example
 +
|desc=The basic usage of '''os.setAlarm''' From a [http://www.computercraft.info/forums2/index.php?/topic/5599-ossetalarm/page__view__findpost__p__46168 forum Post] by jag_e_nummer_ett.
 +
|code= --(( Basic format ))--
 +
os.setAlarm(time)
 +
--(( Will timeout when it's 18 o'clock in the world ))--
 +
os.setAlarm(18.00)
 +
--(( Will timeout 2 (in-game) hours later ))--
 +
os.setAlarm(os.time()+2)
 +
--(( Basic event layout ))--
 +
local ev,p1 = os.pullEvent("alarm")
 +
--(( Event output ))--
 +
Name: alarm
 +
Parameter 1: A table that acts like it's unique ID
 
}}
 
}}
 +
{{Example
 +
|desc=Waits until 5 in the morning and prints a message. From a [http://www.computercraft.info/forums2/index.php?/topic/5599-ossetalarm/page__view__findpost__p__46167 forum Post] by MysticT.
 +
|code= local alarm = os.setAlarm(5)
 +
while true do
 +
    local evt, arg = os.pullEvent("alarm")
 +
    if arg == alarm then
 +
        print("It's 5:00, wake up!")
 +
    end
 +
end
 +
}}
 +
}}
 +
[[Category:Lua_Core_Functions]]

Latest revision as of 21:01, 9 February 2018


Grid Redstone.png  Function os.setAlarm
Adds an alarm which will fire an "alarm" event at the specified Minecraft world time. The returned table acts as a unique ID for the alarm.
Syntax os.setAlarm(number time)
Returns table alarmID
Part of ComputerCraft
API OS

Examples

Grid paper.png  Example
The basic usage of os.setAlarm From a forum Post by jag_e_nummer_ett.
Code
--(( Basic format ))--
os.setAlarm(time)
--(( Will timeout when it's 18 o'clock in the world ))--
os.setAlarm(18.00)
--(( Will timeout 2 (in-game) hours later ))--
os.setAlarm(os.time()+2)
--(( Basic event layout ))--
local ev,p1 = os.pullEvent("alarm")
--(( Event output ))--
Name: alarm
Parameter 1: A table that acts like it's unique ID



Grid paper.png  Example
Waits until 5 in the morning and prints a message. From a forum Post by MysticT.
Code
local alarm = os.setAlarm(5)
while true do
    local evt, arg = os.pullEvent("alarm")
    if arg == alarm then
        print("It's 5:00, wake up!")
    end
end