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

Invisible 'nil' Error

Started by Jman, 13 August 2013 - 12:57 AM
Jman #1
Posted 13 August 2013 - 02:57 AM
So I'm begining to code a lock program on my 1.4.7 computercraft computer and I tested it once before and everything worked perfectly. How ever I wanted to add an space between the "i" string and the "attemtps remaining" text. So I went in and added the space however to my suprise, once I ran the program it started saying "new:44: attempt to call nil". I looked at the code and it has nothing to do with what I changed so I reverted the change to see if the computer was just being annoyingly picky but then it still said it, I looked and looked and can't seem to find any errors. This is a new way of coding for me so it's almost my best work, when I say new II mean applying new methods like string manipulation such as the print functions. Anyways if someone could help me identify this invisible error I would be grateful. oh heres the code.
http://pastebin.com/5YB55Siq
jay5476 #2
Posted 13 August 2013 - 03:30 AM
well I ran your code and entered the correct password and it worked fine try restarting your world or minecraft and try again
svdragster #3
Posted 13 August 2013 - 05:27 AM
I also can't see why this code won't run.

Also if you want to stop people from terminating(Ctrl + T), put

os.pullEvent = os.pullEventRaw
in your code.
TheOddByte #4
Posted 13 August 2013 - 07:46 AM
Just noticed

function printCenter(str, ypos, mode)
  local w,h = term.getSize()
  term.setCursorPos(w/2 - #str/2, ypos)
  if mode == "s" then
    textutils.slowPrint(str)
  elseif mode == "f" then
    print(str)
  end
end

That's your printCenter function and you set the mode as a string
But when you use it you set it like this

printCenter("CODE",7,s) -- S is nil since it hasn't been declared as anything

But i know you meant it to be a string so just do this

printCenter("CODE",7,"s") -- Added " around s so it is a string and can be compared to mode