SCG Banner
Today's birthdays : Scales, Fruit Fencer
icon
Unknown Account
This post is not tied to an account, it may be from before the JB
Discussion: [ComputerCraft] Password-Protected Door Tutorial posted in Archives

Prerequisites:
Computer
Iron Door

Place the computer to the right of the iron door.
Right click the computer to open the terminal.
Create a new file by typing "edit password" (You can replace password with whatever filename you wish)

With the text editor open, type in the following script;

local pw = ""<br />local running = true

This code sets up the two required variables. The first is a string that is used to validate the password. The second is a boolean that informs the program if it should keep going.

while running == true do<br />&nbsp;  term.clear()<br />&nbsp;  write("Please Enter the Password:")<br />&nbsp;  pw = read()

This starts the program loop. term.clear() clears all text on the screen. The program then writes a message and read() reads user input into the pw variable.

&nbsp;  if pw == "furry" then<br />&nbsp; &nbsp; &nbsp; rs.setOutput("left", true)<br />&nbsp; &nbsp; &nbsp; sleep(7)<br />&nbsp; &nbsp; &nbsp; rs.setOutput("left", false)<br />&nbsp;  end

This section tests if the password is correct. If you wish to change the password, change "furry" to whatever you wish. The script then opens the door, waits 7 seconds, and then closes it again. Note: if the door is on the right, change "left" to "right" on both functions.

&nbsp;  if pw == "secretclosephrase" then<br />&nbsp; &nbsp; &nbsp; running = false<br />&nbsp;  end<br />end

This final bit gives us an easy way to exit the program. If the user types "secretclosephrase" instead of the password, the program will close.

Hit the Control key, and use the arrow keys to choose [Save]. Hit control again and close the program. Type "password" into the terminal, and your program should run.

All of the script together:

local pw = ""<br />local running = true<br />while running == true do<br />&nbsp;  term.clear()<br />&nbsp;  write("Please Enter the Password:")<br />&nbsp;  pw = read()<br />&nbsp;  if pw == "furry" then<br />&nbsp; &nbsp; &nbsp; rs.setOutput("left", true)<br />&nbsp; &nbsp; &nbsp; sleep(7)<br />&nbsp; &nbsp; &nbsp; rs.setOutput("left", false)<br />&nbsp;  end<br />&nbsp;  if pw == "secretclosephrase" then<br />&nbsp; &nbsp; &nbsp; running = false<br />&nbsp;  end<br />end<br />

This discussion has no replies...yet.