local eidx= 0 local kHave = true local enemies = {} local function createEnemies(en) local function updateEnemyTable (enemy) enemy:removeSelf() enemy = nil --display.remove( enemy ) --table.remove(enemies,enemy.eidx) print(#enemies) end if kHave then for x = 1, en do eidx = eidx + 1 local enemy = display.newCircle(0, 0, 10) enemy:setFillColor(1,0,0) enemy.x = -200 enemy.y = math.random(150,(display.contentHeight)) enemies[eidx] = enemy transition.to( enemies[eidx], {time = 10000, x = 300--[[display.contentWidth + 200]], onComplete = updateEnemyTable} ) enemies[eidx].eidx = eidx enemies[eidx].myName = "enemy" --enemies[enemy] = enemy --enemy.eidx = eidx --enemy.myName = "enemy" end local function testCollisions() for i = 1, #enemies do if enemies[i].x == 300 or enemies[i].x == nil then --enemies[i].x = 20 --print("reached") --enemies[i]:removeSelf() --enemies[i] = nil --table.remove(enemies, i) else if ( (hero.x \> (enemies[i].x-25)) and (hero.x \< (enemies[i].x+25)) ) and ( (hero.y \> (enemies[i].y-25)) and (hero.y \< (enemies[i].y+25)) ) then kHave = true print("closer to enemy") enemies[i]:setFillColor(0,1,0) --print(enemies[1].x) end end end return kHave end Runtime:addEventListener("enterFrame", testCollisions) end return enemies end local function updateEnemies() createEnemies(1) end timer.performWithDelay( math.random(1000, 3000), updateEnemies, -1 ) \_G.hero = display.newCircle( 10, 10, 10 ) function moveHere(event) transition.to( hero, {time = 2000, x = event.x, y = event.y} ) return hero end Runtime:addEventListener("tap", moveHere)
removing from table through calling index value not working. Why???
Rest all working. I am able to remove from the screen and keep nil but I am not able to remove from the table entirely. Why? Isn’t possible?