Difference between revisions of "Os.setAlarm"
From ComputerCraft Wiki
m (Table -> Table (type)) |
(Added some explanation/example from a forum post, since usage was unclear at best.) |
||
| Line 9: | Line 9: | ||
|examples= | |examples= | ||
}} | }} | ||
| + | == Explanation == | ||
| + | ([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.clock()+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 | ||
| + | </code> | ||
| + | |||
| + | == Example == | ||
| + | ([http://www.computercraft.info/forums2/index.php?/topic/5599-ossetalarm/page__view__findpost__p__46167 Forum Post] by MysticT): | ||
| + | |||
| + | <code> | ||
| + | local alarm = os.startAlarm(5) | ||
| + | while true do | ||
| + | local evt, arg = os.pullEvent("alarm") | ||
| + | if arg == alarm then | ||
| + | print("It's 5:00, wake up!") | ||
| + | end | ||
| + | end | ||
| + | </code> | ||
[[Category:Lua_Core_Functions]] | [[Category:Lua_Core_Functions]] | ||
Revision as of 17:26, 4 March 2013
| 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(float time) |
| Returns | Table alarmID |
| Part of | ComputerCraft |
| API | OS |
Explanation
(Forum Post by jag_e_nummer_ett:)
--(( 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.clock()+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
(Forum Post by MysticT):
local alarm = os.startAlarm(5)
while true do
local evt, arg = os.pullEvent("alarm")
if arg == alarm then
print("It's 5:00, wake up!")
end
end