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

Why isnt thism working?

Started by X3ME, 16 November 2014 - 04:51 PM
X3ME #1
Posted 16 November 2014 - 05:51 PM
Just made this code


local side = "left"
local password = "bacon"
local opentime = 5
while true do
term.clear()
term.setCursorPos(1,1)
write("Password: ")
local input = read("*")
if input == password then
  term.clear()
  term.setCursorPos(1,1)
  print("Password correct!")
  rs.setOutput(side,true)
  sleep(opentime)
  rs.setOutput(side,false)

elseif redstone.getInput ("left") then
  print("Terminal Blocked")
  sleep (3)
 
  else
  print ("Password Incorrect")
  sleep(2)
end
end

So, the porpuse is to be a normal door lock but it doesn't work when it has a redstone signal from the left.

But it dosen't work! Why?
KingofGamesYami #2
Posted 16 November 2014 - 06:06 PM

elseif redstone.getInput ("left") then
  print("Terminal Blocked")
  sleep (3)
 

Remove that entire block and it should work normally, why do you have it in there?
wieselkatze #3
Posted 16 November 2014 - 06:16 PM
I'm pretty sure he meant that it still opens the door, even when the computer has an input from the left side.

The reason for that is, that it only checks for the signal when the password is incorrect.
Just swap the password checking and the redstone part, so it looks like this:

local side = "left"
local password = "bacon"
local opentime = 5
while true do
  term.clear()
  term.setCursorPos(1,1)
  write("Password: ")
  local input = read("*")
  if redstone.getInput ("left") then
    print("Terminal Blocked")
    sleep (3)
  elseif input == password then
    term.clear()
    term.setCursorPos(1,1)
    print("Password correct!")
    rs.setOutput(side,true)
    sleep(opentime)
    rs.setOutput(side,false)
  else
    print ("Password Incorrect")
    sleep(2)
  end
end
Edited on 16 November 2014 - 05:20 PM
X3ME #4
Posted 16 November 2014 - 06:35 PM
I want it to be normal, but i want it to block when it has a rs signal from left
KingofGamesYami #5
Posted 16 November 2014 - 06:40 PM
I want it to be normal, but i want it to block when it has a rs signal from left

In that case, wieselkatze has the fix.