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

Attempt to call nil?

Started by Jud_, 25 May 2014 - 09:50 AM
Jud_ #1
Posted 25 May 2014 - 11:50 AM
So I made this lock on computercraft and for some reason I can't get it to work?
The lock is:

while true do
term.clear ()
term.setCursorPos (1, 1)
print ("Please Enter Door Code:")
lacal input = read("*")
if input == "pass" then
redstone.setOutput("left", true)
sleep(4)
redstone.setOutput("left", false)
else
print ("Code is incorrect!")
sleep(2)
os.shutdown
end
end

However, when I reboot the computer in order to start it, it says
"reboot:3: attempt to call nil
I have no idea what it means so any help would be much appreciated.
wieselkatze #2
Posted 25 May 2014 - 01:28 PM
First of all in line 5, replace lacal with local (I think you didn't copy, but wrote it to the forums by hand).
Also in line 13 you forgot the () for os.shutdown().
Other than that your code should work perfectly.
(You can leave out os.shutdown(), because your code is already in an endless loop.)

Next time, please use code tags(the <> symbol in the editor)and put your code in there.
Edited on 25 May 2014 - 11:29 AM
TheOddByte #3
Posted 25 May 2014 - 11:05 PM
Next time, please use code tags(the <> symbol in the editor)and put your code in there.
or just write
[!CODE] This will be some code [!/CODE] ( without the '!' )
Sir_Mr_Bman #4
Posted 25 May 2014 - 11:23 PM
Fixed formatting:

while true do
  term.clear ()
  term.setCursorPos (1, 1)
  print ("Please Enter Door Code:")
  lacal input = read("*")
  if input == "pass" then
    redstone.setOutput("left", true)
    sleep(4)
    redstone.setOutput("left", false)
  else
    print ("Code is incorrect!")
    sleep(2)
    os.shutdown
  end
end

Debugging:
Line 5: It's local, not lacal.
Line 13: os.shutdown is incorrect. Try os.shutdown()

Also, consider changing your code to:

while true do
  term.clear ()
  term.setCursorPos (1, 1)
  print ("Please Enter Door Code:")
  local input = read("*")
  if input == "pass" then
    redstone.setOutput("left", true)
    sleep(4)
    redstone.setOutput("left", false)
  else
    print ("Code is incorrect!")
    sleep(2)
-- Code that was changed is here... Unneeded....
  end
end
wieselkatze #5
Posted 26 May 2014 - 03:04 PM
-snip-

I wonder if you even read my post. (I wrote the exact same thing 10 hours before)