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:
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
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