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

Advanced Password Door

Started by Macapple, 11 August 2015 - 01:22 PM
Macapple #1
Posted 11 August 2015 - 03:22 PM
Hi Everyone! I'm new to coding, and I can't make a program work as I want to.

Long story short: The program should show a Door State (Open or Locked) i tried doing so with variables, but the program forgets I opened the door, so even if it's opened, it shows it's "Locked"

THE PROGRAM SHOULD

1) Show if a Piston Door is Open/Closed (I figure I'll need a Boolean (?))
2) Ask for Password
3) Open the Door if it's Closed, Close the Door if it's Open
4) Shutdown
5) Must not f&%k up when rebooted

OR

1) Show if Piston Door is Open/Closed
2) Ask Password ONLY when Door is Closed and I want to Open it, and Open It when password is correct.

3) Shutdown
4) Must not f&%k up when rebooted
2.1] If Door is Open, without asking the password, Close the Door, Shutdown.
Edited on 11 August 2015 - 01:25 PM
KingofGamesYami #2
Posted 11 August 2015 - 03:46 PM
If you have code you've written already, please post it. It helps to know what your program looks like, so we can give you solutions specific to your code.

1) You don't need a boolean, if the door is open when a redstone signal is applied, and closed when not, or vice versa. You can simply use rs.getOutput( side ) to detect if you are supplying current or not.
2) Asking for a password is fairly simple, read("*") is often used because it'll show **** instead of the password to anyone who may be watching the terminal at the same time you are.
4) os.shutdown()
5) Probably not needed, but you can use the fs API to make it work.
HPWebcamAble #3
Posted 11 August 2015 - 05:04 PM
If you've already made the door with vanilla redstone, then great, but if not, you can use the computer to open/close it, with my Redstone Engine:
http://www.computercraft.info/forums2/index.php?/topic/21574-redstone-engine/
In the video on ^that page, I actually show how to make a toggle-able door with the program.
Macapple #4
Posted 11 August 2015 - 05:29 PM
If you have code you've written already, please post it. It helps to know what your program looks like, so we can give you solutions specific to your code.
<Omitted>
Here's the code I made on your advice:

local side = "back"
local PASSWORD = "MATRIX"

print(" Aura Node Emboldener MK I ")
print(" Password Required: ")
sleep(1)
if rs.getOutput(side) == true then
print("Door State: Open")
else
print("Door State: Locked")

end
if rs.getOutput(side) == false then
write("Password: ")


  input = read("x")
  if input == PASSWORD then
  print(" Accepted ")
  rs.setOutput(side, true)
  sleep(1)

  elseif input ~= PASSWORD then
  print(" Access Denied " )
  sleep(1)
  end

elseif rs.getOutput(side) == true then
print(" Closing Door ")
sleep(5)
rs.setOutput(side, false)
end

Problems:
1) I want the Computer to Shut Down once it opens the door, but to KEEP giving redstone signal from the Back ('side' variable)
2) I want it not to ask me the password when I want to lock the door, and shutdown afterwards.
KingofGamesYami #5
Posted 11 August 2015 - 05:41 PM
So you want a computer that is off to emit a redstone signal? I don't even know if that's possible. Why do you want it to shutdown anyway?

It shouldn't ask you the password to close the door, given that the redstone output is on when you want to close it.
Twijn #6
Posted 11 August 2015 - 05:44 PM
So you want a computer that is off to emit a redstone signal? I don't even know if that's possible. Why do you want it to shutdown anyway?

It shouldn't ask you the password to close the door, given that the redstone output is on when you want to close it.

Try an RS NOR latch to turn off a signal from a pulse on (for example) the left side of the computer, then to turn it on from the right side.
KingofGamesYami #7
Posted 11 August 2015 - 05:51 PM
If you use Twijn's suggestion, be aware the computer will no longer know if the door is open or closed.
Macapple #8
Posted 11 August 2015 - 05:52 PM
The problem is when i come to use rs.getOutput(side)
Since rebooting shuts the redstone down, it closes the door and asks me the password again.
One thing I could certainly do is latching the output to a Piston Vanilla Toggle Mechanism, and edit the program with a Boolean.
Edited on 11 August 2015 - 03:53 PM
HPWebcamAble #9
Posted 11 August 2015 - 05:54 PM
My advice is: Don't shutdown the computer, it just complicates things.

Of course, you'll need to handle a restart, should someone try to break through by forcing the computer to restart.
Macapple #10
Posted 11 August 2015 - 07:27 PM
I went through the problem of the shutdown by totally revamping the Code.

local side = "back"
local DoorVar = false
local DoorStat = "Closed"
local PAX = "Matrix"

if DoorVar == false then

  print(" Node Emboldener Matrix MK II ")
  sleep(1)
  print("Door Status: "..DoorStat)
  sleep(1)
  textutils.slowPrint("Password Required")
  sleep(0.5)
  textutils.slowWrite("Enter Password: ")
  sleep(0.5)

  input = read("x")
  if input == PAX then
  print(" Password Accepted. Opening Door ")
  rs.setOutput(side, true)
  DoorVar = true
  DoorStat = "Open"
  sleep(1)
  while true do
    print("Press R to Reboot and Close the Door")
  
    local event, key = os.pullEvent("key")
	  if key == keys.r then
	   print(" Rebooting... ")
	   sleep(2)
	   os.reboot()
	   break
	   end
	   end
	  
  elseif input ~= PAX then
  print(" Access Denied. Bad Password. ")
  sleep(3)
  os.reboot()


  else
  print(" Closing Door ")
  rs.setOutput(side, false)
  DoorVar = false

  end
end

As you can see I added a loop at the end of the opening function, so that once finished, one can simply access the Terminal and Press R to Reboot the Terminal and Close the Door.

Thanks everybody for their help!