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

Computercraft door lock 2 passwords with alternate outcomes

Started by daltonguy, 07 January 2014 - 11:33 PM
daltonguy #1
Posted 08 January 2014 - 12:33 AM
Hello I made a door lock with a computer and it all went good but i noticed me going in and out of the room often and wanted to have a password that opened it for a long duration for when I am going in and out, then a short duration open for when I am just going to be a second. I can not for the life of me figure out how to get 2 passwords to read off the same read() and come out with different outcomes. I got them both to work that was not very hard but the door will not close. I can also get them both to work and function properly but you have to type in the second password 2 times to get it to work. This is the pastebin of the code that they both work in the first entry but do not close the door. http://pastebin.com/ZNguBhEW
CometWolf #2
Posted 08 January 2014 - 10:31 AM
I made some quick changes, give it a go. If that dosen't work, you should probably have a look at your doors lol.

while true do
  term.clear()
  term.setCursorPos(1, 1)
  term.write("Enter password:")
  local password = read("*") --the string argument here will make all character input appear as the string, so now all input shows as "*"
  if password == "camdally" then
    redstone.setOutput("left", true)
    sleep(3)
  elseif password == "stay" then --use elseif instead of multiple if's
    redstone.setOutput("left", true)
    sleep(10)
  end
  redstone.setOutput("left", false) -- this would normally be done if any of the passwords were correct, but since all it does is close the door we might aswell call it anyways to be on the safe side
end
OReezy #3
Posted 08 January 2014 - 12:33 PM
For multiple options you want to use elseif statements.

if password == "string" then
  --do something
elseif password == "different string"
  --do something different
end
Edited on 08 January 2014 - 11:33 AM