Jump to content

Recommended Posts

Posted

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

Posted

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.

Posted

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

Posted

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

Posted

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

  • 4 months later...
Posted

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?

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...