Jump to content




Super Simple Door Lock.


  • You cannot reply to this topic
18 replies to this topic

#1 abcdefghijklmnop

  • New Members
  • 8 posts

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


#2 bbc100

  • Members
  • 5 posts

Posted 20 February 2012 - 05:47 AM

can you please put this code into this topic because I cannot see the code

#3 rockymc

  • Members
  • 103 posts

Posted 20 February 2012 - 10:38 AM

Download the archive, open the file in Notepad.

#4 FuzzyPurp

    Part-Time Ninja

  • Members
  • 510 posts
  • LocationHarlem, NY

Posted 20 February 2012 - 01:53 PM

Notepad++

#5 abcdefghijklmnop

  • New Members
  • 8 posts

Posted 20 February 2012 - 02:29 PM

Actually notepad works too ;)/>

#6 FuzzyPurp

    Part-Time Ninja

  • Members
  • 510 posts
  • LocationHarlem, NY

Posted 20 February 2012 - 02:48 PM

View PostBenlego65, on 20 February 2012 - 02:29 PM, said:

Actually notepad works too ;)/>

You should use notepad++ trust me.

#7 abcdefghijklmnop

  • New Members
  • 8 posts

Posted 20 February 2012 - 03:15 PM

I use SciTE, better than both ;)/>

#8 Espen

    Curious Explorer

  • Members
  • 708 posts

Posted 20 February 2012 - 05:12 PM

View PostBenlego65, on 20 February 2012 - 03:15 PM, said:

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.

#9 Advert

    Custom Title

  • Moderators
  • 459 posts
  • LocationLondon

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 ;)/>

#10 abcdefghijklmnop

  • New Members
  • 8 posts

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)

#11 abcdefghijklmnop

  • New Members
  • 8 posts

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.

#12 Espen

    Curious Explorer

  • Members
  • 708 posts

Posted 20 February 2012 - 08:08 PM

View PostBenlego65, on 20 February 2012 - 07:55 PM, said:

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. ;)/>

#13 bbc100

  • Members
  • 5 posts

Posted 26 February 2012 - 06:19 AM

I got all but the output working, how do you get it to work?

#14 hobnob11

  • New Members
  • 10 posts

Posted 26 February 2012 - 02:48 PM

it opens but doesnt close on mine, so after sleep (a)
i put
redstone.Output("left",false)

#15 Jaan

  • New Members
  • 10 posts

Posted 26 February 2012 - 07:18 PM

View Posthobnob11, on 26 February 2012 - 02:48 PM, said:

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)

#16 hobnob11

  • New Members
  • 10 posts

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...

#17 Amunak

  • Members
  • 7 posts

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()


#18 ironsmith123

  • New Members
  • 69 posts

Posted 15 March 2012 - 08:38 PM

View PostAmunak, on 27 February 2012 - 02:55 PM, said:

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?

#19 abcdefghijklmnop

  • New Members
  • 8 posts

Posted 01 April 2012 - 12:08 AM

View Postironsmith123, on 15 March 2012 - 08:38 PM, said:

View PostAmunak, on 27 February 2012 - 02:55 PM, said:

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.)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users