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

2 way powered redstone door

Started by Asaous, 03 October 2014 - 08:27 PM
Asaous #1
Posted 03 October 2014 - 10:27 PM
Hello, so I wanted to setup a door that sends a redstone pulse one way if a password is correct and another if incorrect but I keep getting an error, could someone please help?

os.pullEvent = os.pullEventRaw
correctpass = "1447"
while true do
term.clear()
term.setCursorPos(1,1)
write("Safe Code: ")
local input = read("*")
if input == correctpass then
term.clear()
term.setCursorPos(1,1)
print("Safe Cracked! Enter and contact a staff member to receive your reward!")
rs.setOutput(side,true)
sleep(opentime)
rs.setOutput(side,false)
else

term.clear()
term.setCursorPos(1,1)
print("Failed to Crack Safe! You hear the alarm sounding…")
rs.setOutput(left,true)
sleep(opentime)
rs.setOutput(right,false)
sleep(2) endend
Edited on 03 October 2014 - 08:28 PM
SGunner2014 #2
Posted 03 October 2014 - 10:42 PM
First, use the code function to make your code more readable.
Second, use indentation! It's a lot of fun

Here's the fixed code w/ indentation:

os.pullEvent = os.pullEventRaw
correctpass = "1447"
while true do
term.clear()
term.setCursorPos(1,1)
write("Safe Code: ")
local input = read("*")
if input == correctpass then
  term.clear()
  term.setCursorPos(1,1)
  print("Safe Cracked! Enter and contact a staff member to receive your reward!")
  rs.setOutput(side,true)
  sleep(opentime)
  rs.setOutput(side,false)
else

  term.clear()
  term.setCursorPos(1,1)
  print("Failed to Crack Safe! You hear the alarm sounding...")
  rs.setOutput(left,true)
  sleep(opentime)
  rs.setOutput(right,false)
  sleep(2)
end
end

NB: Replace "side" in the rs.setoutput with a valid side. For example;

rs.setOuput("left",true)

Edit: Also the sides have to be strings
Edited on 03 October 2014 - 08:43 PM
Asaous #3
Posted 03 October 2014 - 11:17 PM
Thank you, it's working now