Jump to content




Open door with detector rail


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

#1 Xixili

  • Members
  • 65 posts
  • LocationChina

Posted 20 July 2014 - 03:23 PM

Hello,

I try to open a door using a detector rail.
When a cart passes the detector rail it should open a door but it doesnt.

if redstone.getInput("left", true) then
sleep(1)
    rs.setOutput("back", true)
sleep(4)
rs.setOutput("right", true)
sleep(2)
end
os.reboot()

The input is the detector rail.
The output BACK is the door
The output right is the holding rail.
When the door is open it should give a signal to the cart that it can go.

#2 hilburn

  • Members
  • 153 posts
  • LocationLondon, England

Posted 20 July 2014 - 03:31 PM

Have you saved this script as startup? if not it will only run once.
A better method of looping is

while true do
    if redstone.getInput("left", true) then
        sleep(1)
        rs.setOutput("back", true)
        sleep(4)
        rs.setOutput("right", true)
        sleep(2)
    end
    sleep(0.1)
end

which will loop forever
although you will also need to set the outputs to false at some point to deactivate the holding rail and close the door

#3 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 20 July 2014 - 05:31 PM

Even better would be to only execute the loop when redstone state has changed.

while true do
  os.pullEvent("redstone")
  if rs.getInput("left") then
    sleep(1)
    rs.setOutput("back", true)
    sleep(4)
    rs.setOutput("right", true)
    sleep(2.1)
    rs.setOutput("right", false)
    rs.setOutput("back", false)
  end
end


#4 Xixili

  • Members
  • 65 posts
  • LocationChina

Posted 20 July 2014 - 05:38 PM

Thanks this will work.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users