SHOW:
|
|
- or go back to the newest paste.
1 | os.pullEvent = os.pullEventRaw -- This prevents people from closing the program with ctrl + t | |
2 | - | -- Password door -- |
2 | + | local side = "left" -- What side is the door on? |
3 | - | -- By adencraft2000 -- |
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 | - | os.pullEvent = os.pullEventRaw |
5 | + | local stayOpen = "stay open password" -- This password will keep the door open |
6 | - | local side = "left" -- What side is the door on, left?right?back? |
6 | + | local opentime = 5 -- How long (With the standard password) should the door stay open? |
7 | - | local password = "password" -- What is the password |
7 | + | |
8 | - | local debug = "debug password" -- What password exits the password mode so you can use the computer? |
8 | + | |
9 | - | local stayOpen = "stay open" -- What makes the door stay open? |
9 | + | while true do -- Keep the program running |
10 | - | local opentime = 5 -- How long will the door stay open for (in seconds) |
10 | + | term.clear() -- Clear the screen of any text |
11 | - | while true do |
11 | + | term.setCursorPos(1,1) -- Set the "cursor" to the top left hand side of the screen |
12 | - | term.clear() |
12 | + | write("Please Input Your Password: ") -- Request password, I used write because it does not start a new line |
13 | - | term.setCursorPos(1,1) |
13 | + | 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 |
14 | - | write("Please Input Your Password: ") |
14 | + | if input == password then -- If what the user entered in was the same as the password defined above |
15 | - | local input = read("*") |
15 | + | term.clear() -- Clear the screen |
16 | - | if input == password then |
16 | + | term.setCursorPos(1,1) -- set cursor to top left corner |
17 | - | term.clear() |
17 | + | print("Password correct!") -- Tell the user they entered the correct password |
18 | - | term.setCursorPos(1,1) |
18 | + | rs.setOutput(side,true) -- sets the redstone output on side (Defined on line 2) to true |
19 | - | print("Password correct!") |
19 | + | sleep(opentime) -- waits for opentime (Defined on line 6) |
20 | - | rs.setOutput(side,true) |
20 | + | rs.setOutput(side,false) -- sets the redstone output on side (Defined on line 2) to false |
21 | - | sleep(opentime) |
21 | + | 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. |
22 | - | rs.setOutput(side,false) |
22 | + | error() -- I have found exit() to print stuff to the console so I used error() to close the program |
23 | - | elseif input == debug then |
23 | + | elseif input == stayOpen then -- another elseif statement, this time seeing if they entered the "stayOpen" password |
24 | - | print("Type password to reactivate door") |
24 | + | rs.setOutput(side,true) -- sets the redstone output on side (Defined on line 2) to true |
25 | - | exit() |
25 | + | term.clear() -- Clear the screen |
26 | - | elseif input == stayOpen then |
26 | + | term.setCursorPos(1,1) -- Set the cursor to top right corner |
27 | - | rs.setOutput(side,true) |
27 | + | print("The door will stay open until you press a key") -- Tell them they need to press a key to close the door |
28 | - | term.clear() |
28 | + | local event, keyCode = os.pullEvent("key") -- this waits for a key press event |
29 | - | term.setCursorPos(1,1) |
29 | + | rs.setOutput(side,false) -- sets the redstone output on side (Defined on line 2) to false |
30 | - | print("The door will stay open until you press space") |
30 | + | else -- If it is not any of those passwords... |
31 | - | local event, keyCode = os.pullEvent("key") |
31 | + | print("Password incorrect!") -- Tell the user that |
32 | - | if keyCode == keys.space then |
32 | + | sleep(2) -- Wait for 2 seconds |
33 | - | rs.setOutput(side,false) |
33 | + | end -- end the if password part |
34 | - | term.clear() |
34 | + | end -- end the while true do loop |