I have an array which holds 55 objects.
On launch I get the number of objects in the array, I have it displayed in a HUD. no problems so far.
However when an object is shot, the array number still holds at 55.
I have removed the objects and nill them out for sure.
I have posted the main bits below, it resides in my main.lua.
I cant get my head around it , any suggestions?
[lua] – create enemy –
function createEnemy(x,y,row)
scene = display.newGroup()
allEnemys = {}
local enemys = require(“modules.enemy”)
for j = 1, 5 do
for i = 1, 11 do
allEnemys[#allEnemys + 1] = enemys:new()
allEnemys[#allEnemys]:init(i * 60, j* 70 +70,j )
allEnemys[#allEnemys]:start()
end
end[/lua]
[lua]
– enemy counter –
onEnterFrame = function( event)
local other = event.other
if (allEnemys) then
local enemyCount = 0
for k,v in pairs (allEnemys) do
enemyCount = enemyCount +1
end
if enemyCount > 20
then
– do somehting –
end
enemyCountHUD.text = enemyCount
end
return true
end
end [/lua]
[lua]Runtime:addEventListener(“enterFrame”, onEnterFrame)[/lua]