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

Can you please fix this code for me? :)

Started by Disy, 07 August 2012 - 06:48 AM
Disy #1
Posted 07 August 2012 - 08:48 AM
Please fix this code for me! Anyways I found it and it doesn't work but I would really like to have a password door with Admin access.
I have already figured out great password door stuff but I have no idea how to make an Admin password that will exit the program.
At the very least though, i'd be very grateful if you could fix this code for me, as i've tried numerous times! Thanks

os.pullEvent = os.pullEventRaw
local side = "right"
local password1 = "1"
local password2 = "2"
local password3 = "3"
local passwordadmin = "admin"
term.clear()
sleep(1)
print("Loading...")
sleep(2)
print("KOP Lock v1.0 Loaded")
print("Welcome to the _____.")
print("To continue please enter password.")
write("Password: ")
local input = read("*")
if input == password1 then
term.clear()
term.setCursorPos(1,1)
print("Password correct!")
print("Welcome ______")
rs.setOutput(side,true)
sleep(4)
rs.setOutput(side,false)
os.reboot()
end
if input == password2 then
term.clear()
term.setCursorPos(1,1)
print("Password correct!")
print("Welcome ______")
rs.setOutput(side,true)
sleep(4)
rs.setOutput(side,false)
os.reboot()
end
if input == password3 then
term.clear()
term.setCursorPos(1,1)
print("Password correct!")
print("Welcome _____")
rs.setOutput(side,true)
sleep(4)
rs.setOutput(side,false)
os.reboot()
end
if input == passwordadmin then
term.clear()
term.setCursorPos(1,1)
print("Password correct!")
print("Computer unlocking...")
print("Please type 'reboot' or 'shutdown' before leaving")
os.pullEvent(terminate)
else
term.clear()
term.setCursorPos(1,1)
print("Password incorrect!")
sleep(2)
os.reboot()
end
Luanub #2
Posted 07 August 2012 - 10:08 AM
Change this line(it's near the end of the code)

os.pullEvent(terminate)


to this:

os.queueEvent("terminate")
ardera #3
Posted 07 August 2012 - 11:56 AM
you can also use error() (if the msg is nil, it will only exit the program)
Cranium #4
Posted 07 August 2012 - 05:59 PM
What you can do to clean up that code a little, is using elseif statements, instead of so many if statements. that way, the program will run a lot smoother.
Disy #5
Posted 07 August 2012 - 08:58 PM
Thanks Guys!