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

Password Door

Started by UP844, 25 January 2013 - 09:48 AM
UP844 #1
Posted 25 January 2013 - 10:48 AM
I have password doors all around my buildings on the server that me and some of my friends own. I was wondering if there was a way to make it so if I turn on a lever then it will run the program, so basically it only has the lock on if it detects redstone current. Here's what I have (saved under startup):
while true do
term.clear()
term.setCursorPos(1, 1)
input = read ("*")
if input == "password" then
redstone.setOutput ("left", true)
sleep(2)
redstone.setOutput ("left", false)

end
end
Instead of while true do could I do if (something that makes the computer detect redstone current) do and then the rest of the coding.
OmegaVest #2
Posted 25 January 2013 - 11:11 AM
Yes, but without the loop, it will only run once.


pass = "someword"  --  Whatever your password is.
lever = "right"  -- Whatever the redstone side is
door = "left"  --  Whatever side the door is on
tArgs = {...}
if #tArgs > 1 then
   print("Usage: \n   password <password>")  -- Or whatever your program name is, goes where the unbracketed password is
elseif tArgs == 1 then
   input = tArgs[1]
end

if input == pass and rs.getInput(lever) then
   rs.setOutput(door, true)
   sleep(2.0)
   rs.setOutput(door, false)
end
term.clear()
term.setCursorPos(1,1)


*The above code will not work with multi-worded passwords. No spaces, and I think no escape characters.

You can add a loop like so:


lever = "right"
door = "left"
pass = "someword"

while true do
   term.clear()
   term.setCursorPos(1,1)
   term.write("Password: ")
   input = read("*")

   if input == pass and rs.getInput(lever) then
      rs.setOutput(door, true)
      sleep(2.0)
      rs.setOutput(door, false)
   end
end
UP844 #3
Posted 25 January 2013 - 12:05 PM
Yes, but without the loop, it will only run once.


pass = "someword"  --  Whatever your password is.
lever = "right"  -- Whatever the redstone side is
door = "left"  --  Whatever side the door is on
tArgs = {...}
if #tArgs > 1 then
   print("Usage: \n   password <password>")  -- Or whatever your program name is, goes where the unbracketed password is
elseif tArgs == 1 then
   input = tArgs[1]
end

if input == pass and rs.getInput(lever) then
   rs.setOutput(door, true)
   sleep(2.0)
   rs.setOutput(door, false)
end
term.clear()
term.setCursorPos(1,1)


*The above code will not work with multi-worded passwords. No spaces, and I think no escape characters.

You can add a loop like so:


lever = "right"
door = "left"
pass = "someword"

while true do
   term.clear()
   term.setCursorPos(1,1)
   term.write("Password: ")
   input = read("*")

   if input == pass and rs.getInput(lever) then
	  rs.setOutput(door, true)
	  sleep(2.0)
	  rs.setOutput(door, false)
   end
end
Thanks!