SHARE
TWEET

[ComputerCraft] Password protected door

adencraft20000 Aug 2nd, 2013 9,669 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. os.pullEvent = os.pullEventRaw -- This prevents people from closing the program with ctrl + t
  2. local side = "left" -- What side is the door on?
  3. local password = "password" -- What is the main password?
  4. local debug = "debug password" -- The debug password will quit the password program allowing you to edit the system
  5. local stayOpen = "stay open password" -- This password will keep the door open
  6. local opentime = 5 -- How long (With the standard password) should the door stay open?
  7.  
  8. --   Password door  --
  9. -- By adencraft2000 --
  10. --[[
  11. This script (like all of mine) is licenced under a creative commons licence:
  12.  
  13. This work is licensed under the Creative Commons Attribution-NonCommercial 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
  14. ]]--
  15.  
  16.  
  17. while true do -- Keep the program running
  18.  term.clear() -- Clear the screen of any text
  19.  term.setCursorPos(1,1) -- Set the "cursor" to the top left hand side of the screen
  20.  write("Please Input Your Password: ") -- Request password, I used write because it does not start a new line
  21.  local input = read("*") -- This defines the local variable "input" and it is equivenent to read("*"), this means that it will store what the user entered in in an attempt to open the door, the read() has a "*" in it so it will print * instead of what the user is entering
  22.  if input == password then -- If what the user entered in was the same as the password defined above
  23.   term.clear() -- Clear the screen
  24.   term.setCursorPos(1,1) -- set cursor to top left corner
  25.   print("Password correct!") -- Tell the user they entered the correct password
  26.   rs.setOutput(side,true) -- sets the redstone output on side (Defined on line 2) to true
  27.   sleep(opentime) -- waits for opentime (Defined on line 6)
  28.   rs.setOutput(side,false) -- sets the redstone output on side (Defined on line 2) to false
  29. elseif input == debug then -- elseif means if it does not match the if statement above then if it matches this elseif statement run it... Here it checks if the user entered the "debug" password.
  30.  error() -- I have found exit() to print stuff to the console so I used error() to close the program
  31. elseif input == stayOpen then -- another elseif statement, this time seeing if they entered the "stayOpen" password
  32.  rs.setOutput(side,true) -- sets the redstone output on side (Defined on line 2) to true
  33.  term.clear() -- Clear the screen
  34.  term.setCursorPos(1,1) -- Set the cursor to top right corner
  35.  print("The door will stay open until you press a key") -- Tell them they need to press a key to close the door
  36.  local event, keyCode = os.pullEvent("key") -- this waits for a key press event
  37.  rs.setOutput(side,false) -- sets the redstone output on side (Defined on line 2) to false
  38. else -- If it is not any of those passwords...
  39.   print("Password incorrect!") -- Tell the user that
  40.   sleep(2) -- Wait for 2 seconds
  41.  end -- end the if password part
  42. end -- end the while true do loop
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top