Posted 17 July 2012 - 10:57 AM
Hi everyone,
My computer gives the error: attempt to compare nil with number (at line 38) in this code (it's a door lock with tries):
I know what the error means, but I have no idea what I'm doing wrong…
My computer gives the error: attempt to compare nil with number (at line 38) in this code (it's a door lock with tries):
function clear()
term.clear()
term.setCursorPos(1,1)
end
function tries()
triesLeft = triesLeft - 1
end
function enterPass()
write("Password: ")
password = read("*")
end
function correct()
print("Password correct!")
rs.setOutput("back", true)
sleep(4)
rs.setOutput("back", false)
end
tiresLeft = 3
os.pullEvent = os.pullEventRaw
term.redirect(peripheral.wrap("right"))
clear()
print("Enter password to open")
term.restore()
clear()
print("Enter password to open")
enterPass()
if password == "Mypass" then
clear()
correct()
else
while password ~= "Mypass" and triesLeft >= 0 do
clear()
print("Password incorrect, try again")
print("Tries left: "..triesLeft)
enterPass()
tries()
end
if triesLeft == 0 then
print("You have no tries left")
while true do
print("")
end
elseif password == "Mypass" then
correct()
end
end
The prgram starts good, but when it enters the loop at line 38 it gives the error. Also, when you enter the correct password, it works without errors.I know what the error means, but I have no idea what I'm doing wrong…