Anyone know how to automatic lock and open the door with time?
Sorry for my english and... thanks before
[ASK]How to automatic lock and open the door with time
Started by digigir, Jan 06 2013 01:25 AM
5 replies to this topic
#1
Posted 06 January 2013 - 01:25 AM
#2
Posted 06 January 2013 - 04:42 AM
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
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
#4
Posted 06 January 2013 - 05:27 AM
I think he means something like this:
I would rather do this though:
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:
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.
#5
Posted 06 January 2013 - 02:21 PM
Orwell, on 06 January 2013 - 05:27 AM, said:
I think he means something like this:
I would rather do this though:
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:
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.#6
Posted 06 January 2013 - 02:24 PM
<p>Thanks, your example help me
Orwell, on 06 January 2013 - 05:27 AM, said:
I think he means something like this:
I would rather do this though:
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:
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.2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











