Jump to content

Door locking with computer


Recommended Posts

Hello people,

I just watched a tutorial saying how to lock a door with an computer, for this case I used the computer on the right side of the door:

print("Enter Password:")

answer = read()

if answer== "password" then

print("Password correct")

redstone.setOutput("left",true)

sleep(5)

redstone.setOutput("left",false)

os.shutdown()

end

I was wondering, can I also let the os shutdown if something else is typed in?

thanks already :D

Link to comment
Share on other sites

Hmm, maybe something like this?

print("Enter Password: ")

answer = read()

if answer == "password" then

print("Access Granted.")

redstone.setOutput("left",true)

sleep(5)

redstone.setOutput("left",false)

os.shutdown()

end

else

print("Access Denied.")

sleep(5)

os.shutdown()

end

I'm unsure of the syntax, but that's the logic.

Link to comment
Share on other sites

Hmm, maybe something like this?

print("Enter Password: ")

answer = read()

if answer == "password" then

print("Access Granted.")

redstone.setOutput("left",true)

sleep(5)

redstone.setOutput("left",false)

os.shutdown()

end

else

print("Access Denied.")

sleep(5)

os.shutdown()

end

I'm unsure of the syntax, but that's the logic.

I used eof at the 11th line, and it sais it expected an = at the 12th line?

I do not know much of this, but it seems legit for how far I can tell :D. Only the cpu doesn't think its legit...

Link to comment
Share on other sites

I used eof at the 11th line, and it sais it expected an = at the 12th line?

I do not know much of this, but it seems legit for how far I can tell :D. Only the cpu doesn't think its legit...

Found the problem :D the end in the middle does seem to screw all the stuff up, its pretty stupid of me to forget that...

Link to comment
Share on other sites

Hmm, maybe something like this?

print("Enter Password: ")

answer = read()

if answer == "password" then

print("Access Granted.")

redstone.setOutput("left",true)

sleep(5)

redstone.setOutput("left",false)

os.shutdown()

end

else

print("Access Denied.")

sleep(5)

os.shutdown()

end

I'm unsure of the syntax, but that's the logic.

I have set it to:

print("Enter Password: ")

answer = read()

if answer == "password" then

print("Access Granted.")

redstone.setOutput("left",true)

sleep(5)

redstone.setOutput("left",false)

os.shutdown()

else

print("Access Denied.")

sleep(5)

os.shutdown()

Link to comment
Share on other sites

  • 4 months later...

Question i am looking for a good way to learn to program the computer for my own needs ( mostly security door that will active a forcefield containment protocol in the case of an attempted breakin ) maybe an added alarm or even activating my industrial tesslacoil given a number of invalid pass code entries. Have any ideas?

Link to comment
Share on other sites

I have set it to:

print("Enter Password: ")

answer = read()

if answer == "password" then

print("Access Granted.")

redstone.setOutput("left",true)

sleep(5)

redstone.setOutput("left",false)

os.shutdown()

else

print("Access Denied.")

sleep(5)

os.shutdown()

You may want to try this:

os.pullEvent = os.pullEventRaw
local side = "left" -- Change left to whatever side your door / redstone is on.
local password = "bacon" -- Change bacon to what you want your password to be. Be sure to leave the "s around it, though
local opentime = 5 -- Change 5 to how long (in seconds) you want the redstone current to be on. 
while true do 
 term.clear() -- Clears the screen
 term.setCursorPos(1,1) -- Fixes the cursor position
 write("Password: ") -- Prints 'Password: ' to the screen
 local input = read("*") -- Makes the variable 'input' have the contents of what the user types in.
 if input == password then -- Checks if the user inputted the correct password
  term.clear() -- Already explained up top
  term.setCursorPos(1,1)
  print("Password correct!") -- Prints 'Password correct!' to the screen
  rs.setOutput(side,true) -- Output a redstone current to the side you specified
  sleep(opentime) -- Wait the amount of seconds you specifed, then..
  rs.setOutput(side,false) -- Stop outputting a redstone current
 else -- Checks if the user didn't input the correct password
  print("Password incorrect!") -- Prints 'Password incorrect!' to the screen
  sleep(2) -- Waits 2 seconds
 end
end
This is not my code, I coppied it from here and edited some of the comments for length.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...