Jump to content




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


  • You cannot reply to this topic
5 replies to this topic

#1 digigir

  • New Members
  • 4 posts
  • LocationBandung, Indonesia

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

#2 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

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

#3 digigir

  • New Members
  • 4 posts
  • LocationBandung, Indonesia

Posted 06 January 2013 - 05:07 AM

View PostremiX, on 06 January 2013 - 04:42 AM, said:

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

#4 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

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.

#5 digigir

  • New Members
  • 4 posts
  • LocationBandung, Indonesia

Posted 06 January 2013 - 02:21 PM

View PostOrwell, on 06 January 2013 - 05:27 AM, said:

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

#6 digigir

  • New Members
  • 4 posts
  • LocationBandung, Indonesia

Posted 06 January 2013 - 02:24 PM

<p>

View PostOrwell, on 06 January 2013 - 05:27 AM, said:

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





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users