Error claims a value is nil, which makes no sense
Posted: Fri Sep 01, 2017 1:01 am
Everytime I attempt to run my code I get an error that says a value in my if statement is nil.
The if statement in question:
Ive managed to narrow it down to it thinking that rX[n] is nil. The absolutely baffling thing is that they are both being called from this:
Which means that i and n are the same value. So it is literelly comparing rX[1] and rX[1] and says that one is nil and the other is fine. Does anyone have any idea what this could mean? I have tried everything I can think of, at this point I'm certain the solution is some dumb typo I made that is just flying over my head. Here is all the relevant code:
The if statement in question:
Code: Select all
elseif rX[i] < rX[n] + 2 and rX[n] < rX[i] + 2 and rY[i] < rY[n] + 2 and rY[n] < rY[i] + 2 then
Code: Select all
for i = 1, #rX do
for n = 1, #rX do
if isCollided(i, n) then
Code: Select all
function doFights()
for i = 1, #rX do
for n = 1, #rX do
if isCollided(i, n) then
if rS[i] > rS[n] then
table.remove(rX, n)
table.remove(rY, n)
table.remove(rS, n)
elseif rS[i] < rS[n] then
table.remove(rX, i)
table.remove(rY, i)
table.remove(rS, i)
elseif rS[i] == rS[n] then
if love.math.random(0, 1) == 0 then
table.remove(rX, n)
table.remove(rY, n)
table.remove(rS, n)
else
table.remove(rX, i)
table.remove(rY, i)
table.remove(rS, i)
end
end
end
end
end
end
function isCollided(i, n)
if rX[i] < rX[n] + 2 and rX[n] < rX[i] + 2 and rY[i] < rY[n] + 2 and rY[n] < rY[i] + 2 then
return 1
else
return 0
end
end