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

Open door with detector rail

Started by Xixili, 20 July 2014 - 02:23 PM
Xixili #1
Posted 20 July 2014 - 04: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.
hilburn #2
Posted 20 July 2014 - 04: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
Lyqyd #3
Posted 20 July 2014 - 06: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
Xixili #4
Posted 20 July 2014 - 06:38 PM
Thanks this will work.