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

Need Help, Door Lock Code!

Started by whos_Blu, 21 November 2012 - 12:33 PM
whos_Blu #1
Posted 21 November 2012 - 01:33 PM
function lock()
term.clear()
term.setCursorPos(1,1)

correctpass = "bitchboy"

write("Please Enter Passcode: ")

pass = read()

if pass == (correctpass) then
write("Access Granted!")
redstone.setOutput("right",true)
sleep(1)
redstone.setOutput("right",false)

else
write("Access Denied!")
sleep(1)
os.reboot()
lock()
end
end
lock()

This code does work fine, but right after the reboot, the program runs itself again for a split second, then the end command takes its turn and restarts the program. Basically after the program runs, it pops up again for a split second, then pops up again for the actual start of the program. Its sort of like a flash of the program before it actually starts up again. Sorry if i couldn't explain it well, but if you make this code a program for yourself, you could see what i mean. Please help, it looks kinda weird with the flash and all. Thanks in advance!

EDIT - Just found another problem with my code! When the correct password is typed in and submitted, It brings up the rugular computer "> _" flashing thing and the program dosen't restart itself like its supposed to do.
anonimo182 #2
Posted 21 November 2012 - 01:40 PM

function lock()
term.clear()
term.setCursorPos(1,1)
correctpass = "bitchboy"
write("Please Enter Passcode: ")
pass = read()
if pass == (correctpass) then
write("Access Granted!")
redstone.setOutput("right",true)
sleep(1)
redstone.setOutput("right",false)
else
write("Access Denied!")
sleep(1)
os.reboot()
end
You have had too many ends and a function that is not there
whos_Blu #3
Posted 21 November 2012 - 01:58 PM

function lock()
term.clear()
term.setCursorPos(1,1)
correctpass = "bitchboy"
write("Please Enter Passcode: ")
pass = read()
if pass == (correctpass) then
write("Access Granted!")
redstone.setOutput("right",true)
sleep(1)
redstone.setOutput("right",false)
else
write("Access Denied!")
sleep(1)
os.reboot()
end
You have had too many ends and a function that is not there

Well, the other End is to close the "lost()" in line 1. I got a error using the code your provided.

"bios:206: [string "startup"]:16: 'end' expected (to close 'function' at line 1)"
trogdor17 #4
Posted 21 November 2012 - 04:04 PM
The problem is that the function "lock" in your code is only called once. You need to use a while true do loop to make the code will run again.

pass = "this is the password"
function lock()
while true do
input =""
term.clear()
term.setCursorPos(1,1)
print("Please Enter The Password:")
input = read("*") -- the parameter will replace what you type
if input == pass then
rs.setOutput("right",true)
sleep(3) -- change to the number of seconds you want the door open
rs.setOutput("right",false)
else print("WRONG PASSWORD!")
sleep(2)
end
end
end
lock()
try that, it also replaces what you type with a *
remiX #5
Posted 21 November 2012 - 11:09 PM
Also name the program 'startup' within the computer.