Posted 06 January 2013 - 01:25 AM
Anyone know how to automatic lock and open the door with time?
Sorry for my english and… thanks before
Sorry for my english and… thanks before
ok thanks…. but can you make a example? it will help for noob :D/>Time? You mean minecraft time?
Use os.time() and format it and then get the time and when its 6 in the morning, open the door, when its 6 at night, close
while true do
local time = textutils.formatTime(os.time(), true)
if time == "6:00" then
-- turn lights off
elseif time == "18:00" then
-- turn lights on
end
sleep(0)
end
local dawn = os.startTimer(6)
local sunset = os.startTimer(18)
while true do
local e,timer = os.pullEvent("timer")
if timer == dawn then
dawn = os.startTimer(6)
-- turn off lights
elseif timer == sunset then
sunset = os.startTimer(18)
-- turn on lights
end
end
You could refine this a bit more, it's just an example.Thanks your example help me :)/> :)/> :)/>I think he means something like this:while true do local time = textutils.formatTime(os.time(), true) if time == "6:00" then -- turn lights off elseif time == "18:00" then -- turn lights on end sleep(0) end
I would rather do this though:You could refine this a bit more, it's just an example.local dawn = os.startTimer(6) local sunset = os.startTimer(18) while true do local e,timer = os.pullEvent("timer") if timer == dawn then dawn = os.startTimer(6) -- turn off lights elseif timer == sunset then sunset = os.startTimer(18) -- turn on lights end end
Thanks, your example help me :)/> :)/>I think he means something like this:while true do local time = textutils.formatTime(os.time(), true) if time == "6:00" then -- turn lights off elseif time == "18:00" then -- turn lights on end sleep(0) end
I would rather do this though:You could refine this a bit more, it's just an example.local dawn = os.startTimer(6) local sunset = os.startTimer(18) while true do local e,timer = os.pullEvent("timer") if timer == dawn then dawn = os.startTimer(6) -- turn off lights elseif timer == sunset then sunset = os.startTimer(18) -- turn on lights end end