First, set up the door - a computer next to an iron door. If you are good at redstone, you can set up a piston door, but don't worry about that.
Now, go onto the computer and type "edit startup". This will allow you to edit what happens when you boot up the computer.
You will now be presented with a black area and text at the bottom saying "Press CTRL to access the menu" and the line count.
Start off by typing the following:
os.pullEvent = os.pullEventRaw
This will stop people from terminating the lock and opening the door without the password.Next, we will define three things. Where the redstone/door is located, the password and how long the door will stay open for. To do this, type:
local doorLocation = "side_goes_here"
local password = "password_goes_here"
local sleepTime = time_in_seconds
Replace the "side_goes_here" with where the door/redstone is located on the computer (e.g: front,back,right,left,bottom,top)Replace the "password_goes_here" with the password you want to be able to open the door with.
Replace the "time_in_seconds" to a number - that number being how long you want the door to stay open for. Do not put speech marks around this.
Next, type the following block of code:
while true do
write("Enter the password: ")
input = read("*")
if input == password then
print("Password Correct!")
redstone.setOutput(doorLocation, true)
sleep(sleepTime)
redstone.setOutput(doorLocation, false)
term.clear()
term.setCursorPos(1,1)
else
print("Incorrect Password! Try again!")
sleep(sleepTime)
term.clear()
term.setCursorPos(1,1)
end
end
Now for some explaining. The "while true do" part starts a loop for the program to execute, so it will constantly ask for the password.The write part asks you for the password, this will appear on the screen.
The next line puts what you type into a variable called "input". The program then checks the contents of this variable against the password you defined earlier on. If the password is correct, the door will open and print to the screen that the password is correct, then, after the set amount of time (the sleepTime variable), the door will close and the screen will be cleared then the code will repeat. The "else" section will be the part that gets executed if you get the password wrong. It will print that the password is incorrect then sleep for the defined amount of time and then clear the terminal. Then it will end the if statement and the loop.
So there you go, pretty long post, but it means you can add security to your home or other buildings!
Hope this helps alot of begginners to Lua or ComputerCraft.
_Zircon_
EDIT: I forgot that it is Lua not LUA! :(/>