jumpandshootbeef Posted January 17, 2014 Posted January 17, 2014 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 Quote
dwwojcik Posted January 17, 2014 Posted January 17, 2014 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. Quote
jumpandshootbeef Posted January 18, 2014 Author Posted January 18, 2014 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 . Only the cpu doesn't think its legit... Quote
jumpandshootbeef Posted January 18, 2014 Author Posted January 18, 2014 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 . Only the cpu doesn't think its legit... Found the problem the end in the middle does seem to screw all the stuff up, its pretty stupid of me to forget that... Quote
jumpandshootbeef Posted January 18, 2014 Author Posted January 18, 2014 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() Quote
nightdemonic Posted June 12, 2014 Posted June 12, 2014 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? Quote
PBlock96 Posted June 15, 2014 Posted June 15, 2014 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.