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

Mapping: attempt to perform arithmetic __add on nil and number

Started by Abahu, 29 March 2014 - 02:53 AM
Abahu #1
Posted 29 March 2014 - 03:53 AM
Normally, I know what to do with errors, especially the "attempted to perform arithmetic" and then something about adding a string and a number or a number and nil. This time, I'm utterly confused. I'm creating a building program that allows for a user to design a build with the maximum dimensions of 64X12X64, so naturally I'm using jagged arrays for my mapping. The way the display works, I have to handle exceptions for when the cursor is close to the edges of the allotted boundaries else I'll get errors saying I'm trying to pull a number from a non-existent table value. That's what this bit of code does:


for xv = 1, 50 do
for yv = 4, 18 do
  term.setCursorPos(xv,yv)
  if cx+xv-25 >= 1 and xy+yv-9 >= 1 then
   cm = a[lvl][cx+xv-25][cy+yv-9]
   if cm ~= 0 then
	term.write(tostring(cm))
   else
	term.write(" ")
   end
  else
   term.write("!")
  end
end
end

However, on the first if-statement, I get the error that I attempted to perform arithmetic by adding a nil and a number. My confusion is: why is this happening? All of the variables are declared as numbers, so what is the problem? Any help would be great.

Link to the pastebin for the full code: http://pastebin.com/0iCH5nbb
Lyqyd #2
Posted 29 March 2014 - 04:04 AM
xy does not appear to have been given a value.
Abahu #3
Posted 29 March 2014 - 06:04 AM
Oh my goodness… thank you. That was supposed to be cy xD Again, thank you.