Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent = os.pullEventRaw -- This prevents people from closing the program with ctrl + t
- local side = "left" -- What side is the door on?
- local password = "password" -- What is the main password?
- local debug = "debug password" -- The debug password will quit the password program allowing you to edit the system
- local stayOpen = "stay open password" -- This password will keep the door open
- local opentime = 5 -- How long (With the standard password) should the door stay open?
- while true do -- Keep the program running
- term.clear() -- Clear the screen of any text
- term.setCursorPos(1,1) -- Set the "cursor" to the top left hand side of the screen
- write("Please Input Your Password: ") -- Request password, I used write because it does not start a new line
- 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
- if input == password then -- If what the user entered in was the same as the password defined above
- term.clear() -- Clear the screen
- term.setCursorPos(1,1) -- set cursor to top left corner
- print("Password correct!") -- Tell the user they entered the correct password
- rs.setOutput(side,true) -- sets the redstone output on side (Defined on line 2) to true
- sleep(opentime) -- waits for opentime (Defined on line 6)
- rs.setOutput(side,false) -- sets the redstone output on side (Defined on line 2) to false
- 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.
- error() -- I have found exit() to print stuff to the console so I used error() to close the program
- elseif input == stayOpen then -- another elseif statement, this time seeing if they entered the "stayOpen" password
- rs.setOutput(side,true) -- sets the redstone output on side (Defined on line 2) to true
- term.clear() -- Clear the screen
- term.setCursorPos(1,1) -- Set the cursor to top right corner
- print("The door will stay open until you press a key") -- Tell them they need to press a key to close the door
- local event, keyCode = os.pullEvent("key") -- this waits for a key press event
- rs.setOutput(side,false) -- sets the redstone output on side (Defined on line 2) to false
- else -- If it is not any of those passwords...
- print("Password incorrect!") -- Tell the user that
- sleep(2) -- Wait for 2 seconds
- end -- end the if password part
- end -- end the while true do loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement