This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
digigir's profile picture

[ASK]How to automatic lock and open the door with time

Started by digigir, 06 January 2013 - 12:25 AM
digigir #1
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
remiX #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
digigir #3
Posted 06 January 2013 - 05:07 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
ok thanks…. but can you make a example? it will help for noob :D/>
Orwell #4
Posted 06 January 2013 - 05:27 AM
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:

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.
digigir #5
Posted 06 January 2013 - 02:21 PM
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:

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 :)/> :)/> :)/>
digigir #6
Posted 06 January 2013 - 02:24 PM
<p>
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:

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 :)/> :)/>