This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
abcdefghijklmnop's profile picture

Super Simple Door Lock.

Started by abcdefghijklmnop, 20 February 2012 - 02:49 AM
abcdefghijklmnop #1
Posted 20 February 2012 - 03:49 AM
A tiny little script for locking a door.
It also gives you a prompt to enter a time amount (in seconds) for how long the door will stay open!
PS; look through the entire thing. If you see anything with { }, then edit what is inside (and remove the brackets).
Enjoy!
EDIT: updated, Espen changed around some of the code to make it better.

Also, because someone requested the code instead of the archive, here it is.


local function clearScreen()
term.clear()
term.setCursorPos(1, 1)
end
while true do
clearScreen()
print ("Type password to enter {LOCATION}!")
if read("*") == "{PASSWORD}" then
clearScreen()
print("Correct Password!")
print("Open door for how long?")
local a = read()
clearScreen()
print("Opening door!")
sleep (1)
redstone.setOutput("{SIDE OF DOOR}",true)
clearScreen()
sleep (a)
else
clearScreen()
print("Incorrect Password, please try again.")
sleep (5)
end
end
bbc100 #2
Posted 20 February 2012 - 05:47 AM
can you please put this code into this topic because I cannot see the code
rockymc #3
Posted 20 February 2012 - 10:38 AM
Download the archive, open the file in Notepad.
FuzzyPurp #4
Posted 20 February 2012 - 01:53 PM
Notepad++
abcdefghijklmnop #5
Posted 20 February 2012 - 02:29 PM
Actually notepad works too ;)/>/>
FuzzyPurp #6
Posted 20 February 2012 - 02:48 PM
Actually notepad works too ;)/>/>

You should use notepad++ trust me.
abcdefghijklmnop #7
Posted 20 February 2012 - 03:15 PM
I use SciTE, better than both ;)/>/>
Espen #8
Posted 20 February 2012 - 05:12 PM
I use SciTE, better (for me) than both :)/>/>
Fixed that for ya. ;)/>/>
Nothing is intrinsically better than something else. Worth lies in the eye of the beholder.
And since all beholders are not the same, they assign different values to things.
Ergo some things which are better for some are worse for others and vice versa.
Advert #9
Posted 20 February 2012 - 05:47 PM
I'd suggest you use read("*") instead of read(), as this will prevent you from reading the password as someone else is entering it.

You could also use configuration variables at the start of the file, e.g

local password = "2good4u" -- password
local side = "left" -- side to toggle redstone
local duration = 3; -- duration to keep door open


Further derailing this topic:
I'm currently trying IntelliJ IDEA with a Lua plugin; I haven't used it that much (since I haven't coded much since installing and configuring it).

I would definitely agree with Espen, though; you should use whatever you like to use.
I switched because I like trying new stuff every now and then ;)/>/>
abcdefghijklmnop #10
Posted 20 February 2012 - 07:49 PM
I really just ended up continuing the argument for the point of having an argument, nothing else.
THANKS! I wanted to make it do that, but didn't know how xD
I'll put it in.
(I mean hiding the password)
abcdefghijklmnop #11
Posted 20 February 2012 - 07:55 PM
Also, Espen, with how you had the terminal clear after the password was entered, it would have a blank line THEN say "Correct password!"
I fixed it.
Espen #12
Posted 20 February 2012 - 08:08 PM
Also, Espen, with how you had the terminal clear after the password was entered, it would have a blank line THEN say "Correct password!"
I fixed it.
I was confused for a moment what you are talking about. But then I remembered that you're referring to my post on the other forum.^^
Yeah, I didn't really run the code to test it. Just wanted to give you some pointers of how to remove some redundancies with the shell.run() thing.
But glad that you were able to fix it, that's all that counts. ;)/>/>
bbc100 #13
Posted 26 February 2012 - 06:19 AM
I got all but the output working, how do you get it to work?
hobnob11 #14
Posted 26 February 2012 - 02:48 PM
it opens but doesnt close on mine, so after sleep (a)
i put
redstone.Output("left",false)
Jaan #15
Posted 26 February 2012 - 07:18 PM
it opens but doesnt close on mine, so after sleep (a)
i put
redstone.Output("left",false)

You need to do redstone.setOutput("left",false) or rs.setOutput("left",false)
hobnob11 #16
Posted 27 February 2012 - 12:48 PM
can someone help me make this program so that the program cannot be terminated, i tried using pcall infront of all the reads and sleeps but that didnt work…
Amunak #17
Posted 27 February 2012 - 02:55 PM
I have improved the password script to be more clean and re-usable:


local rsout = "bottom" -- this is the face of the computer where we want to have the redstone output
local p = "secret" -- set your password here
local function clear()
  term.clear()
  term.setCursorPos(1, 1)
end
local function pass(p)
  clear()
  write("Enter password: ")
  if read("*") == p then
	clear()
	write("Access granted.")
	sleep(2)
	clear()
	return true
  else
	clear()
	write("Incorrect password.")
	sleep(2)
	clear()
	return false
  end
end
repeat
  g = pass(p)
until g == true


-- do something when the password is correct

redstone.setOutput(rsout,true)
sleep(0.1)
redstone.setOutput(rsout,false) -- send only a tick - I prefer using redstone (redpower) for timing, timed closing, etc.
write("Redstone tick (position: "..rsout..") sent.n")
write("Shutting down.")
sleep(2)
os.shutdown()
ironsmith123 #18
Posted 15 March 2012 - 08:38 PM
I have improved the password script to be more clean and re-usable:


local rsout = "bottom" -- this is the face of the computer where we want to have the redstone output
local p = "secret" -- set your password here
local function clear()
  term.clear()
  term.setCursorPos(1, 1)
end
local function pass(p)
  clear()
  write("Enter password: ")
  if read("*") == p then
	clear()
	write("Access granted.")
	sleep(2)
	clear()
	return true
  else
	clear()
	write("Incorrect password.")
	sleep(2)
	clear()
	return false
  end
end
repeat
  g = pass(p)
until g == true


-- do something when the password is correct

redstone.setOutput(rsout,true)
sleep(0.1)
redstone.setOutput(rsout,false) -- send only a tick - I prefer using redstone (redpower) for timing, timed closing, etc.
write("Redstone tick (position: "..rsout..") sent.n")
write("Shutting down.")
sleep(2)
os.shutdown()
How would i change the amount of time that the door stayed open?
abcdefghijklmnop #19
Posted 01 April 2012 - 01:08 AM
I have improved the password script to be more clean and re-usable:


local rsout = "bottom" -- this is the face of the computer where we want to have the redstone output
local p = "secret" -- set your password here
local function clear()
  term.clear()
  term.setCursorPos(1, 1)
end
local function pass(p
  clear()
  write("Enter password: ")
  if read("*") == p then
	clear()
	write("Access granted.")
	sleep(2)
	clear()
	return true
  else
	clear()
	write("Incorrect password.")
	sleep(2)
	clear()
	return false
  end
end
repeat
  g = pass(p)
until g == true


-- do something when the password is correct

redstone.setOutput(rsout,true)
sleep(0.1)
redstone.setOutput(rsout,false) -- send only a tick - I prefer using redstone (redpower) for timing, timed closing, etc.
write("Redstone tick (position: "..rsout..") sent.n")
write("Shutting down.")
sleep(2)
os.shutdown()
How would i change the amount of time that the door stayed open?
With the original version, made by me (and edited by Espen :o/>/>), once you enter the password, the terminal asks for an amount of time (in seconds) for the door to stay open.
Hope this helps :o/>/>
(PS.; you can also add a sleep({time}) at any point in the code to make it sleep for {time} seconds. Remember to replace {time} with a number.)