I am getting an error which I cannot figure out the solution even though I know the issue.
Im moving objects across the screen and they should destroy once they left the screen. When the code for removing the object (which has passed the screen) runs, I get this error:
Attempt to index field '?' (a nil value)
Here is my code…
if (gemsGroup ~= nil ) then for i = 1, gemsGroup.numChildren do if gemsGroup[i].x \< bounds.x then gemsGroup:remove(gemsGroup[i]) print("Destroyed") else gemsGroup[i].x = gemsGroup[i].x - speed print("Keep moving across") end end end
This is the line that is causing the error after the destroy condition has run.
if gemsGroup[i].x \< 100 then
I understand that it is probably nil when trying to compare its location but it should be comparing to the objects not removed last go. Please help as I am confused.
Thanks