Dear all,
i am facing an issue, i have a table called R2Lobjects and i insert all my enemies in it and when i shoot the enemy in the onCollssion function i do this
[lua]–
if (event.object1.objectType == “food”) then
event.object1:removeSelf();
event.object1 = nil
score = score + 1;
end
–[/lua]
but when i exit the scene i call on the cleanObject function to clear the memory i always get an error that i am indexing to a nil value but if i did not shoot anything and call this function it works can anyone please help
[lua]–
function clearObjects()
for i=#R2LObjects,1,-1 do
local child = table.remove(R2LObjects, i) – Remove from table
if child ~= nil then
print ("object deleted = "… i)
child:removeSelf()
child = nil
end
end
R2LObjects = nil
R2LObjects = {}
collectgarbage()
end
–[/lua]
