Jump to content




How to make a *simple* door lock!

computer lua utility

8 replies to this topic

#1 Astrophylite

  • Members
  • 121 posts
  • Locationgps.locate()

Posted 03 July 2015 - 03:28 PM

Just sharing something pretty simple, a door lock.
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! :(

Edited by _zircon_, 24 October 2015 - 09:29 PM.


#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 03 July 2015 - 07:24 PM

Moved to Tutorials.

#3 Xanomes

  • Members
  • 4 posts

Posted 13 August 2015 - 08:51 PM

Thanks for this awesome tutorial, it helped me a lot :)

#4 Astrophylite

  • Members
  • 121 posts
  • Locationgps.locate()

Posted 18 August 2015 - 08:41 PM

View PostXanomes, on 13 August 2015 - 08:51 PM, said:

Thanks for this awesome tutorial, it helped me a lot :)
Glad I could help someone ;)

#5 bbc100

  • Members
  • 5 posts

Posted 01 November 2015 - 12:32 AM

This doesn't work for me

EDIT: I got it to work now, how do I edit it after I create it?

Edited by bbc100, 01 November 2015 - 12:39 AM.


#6 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 01 November 2015 - 12:40 AM

What exactly so you mean?

#7 Kristopher_Jones

  • Members
  • 16 posts
  • LocationLatvia

Posted 01 November 2015 - 09:27 AM

This is really helpfull, thank you!

#8 bbc100

  • Members
  • 5 posts

Posted 02 November 2015 - 08:25 AM

Now it comes up with 1:12: Expected string, boolean

#9 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 02 November 2015 - 09:28 AM

Without seeing the code you're using to generate that error, we can only guess; but a shot in the dark is that you might be miss-using redstone.setOutput(). Make sure you're passing it a string and a boolean.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users