A lot people seem to be having this problem and i still haven’t found a fix for it. I’ve searched all over the web. Maybe i’m just being a little shallow but i dont think Corona people have found a fix for this.
I am creating an instance of a display object, once that instance is created, i add to to my local display group. It works fine the first time i load that scene. But after game over or if i retry that scene, when i try to create the display object again, i get an insert error. The scene was completely purged() and removed() yet i keep getting an insert error.
Globals.lua:
TableOfBullets = {}
TableOfBulletsIndex = 0
BulletClass.lua:
function newBullet(Type, Muzzle, EndPoint, Damage)
... some code
if(Type == "Normal") then
ThisBullet = display.newRect(Muzzle.x, Muzzle.y, 5, 20)
end
... some more code
return ThisBullet
end
Stage1:
function scene:createScene( event )
local Stage1DisplayGroup = self.view
-- HUD display layer for pause button, aiming cursor and text displays.
local HUD\_DisplayLayer = display.newGroup()
-- Game action layer for player, bullets, explosions and enemies.
local GameActionLayer = display.newGroup()
... some code
local function checkActions()
if(PlayerIsTouchingTheScreen == true) then
local Fired = false
Fired = fireWeapon(MainCharacter, Weapons[GAMEINV\_EquipedWeapon])
-- If a bullet was fired.
if(Fired == true) then
-- Create the bullet
TableOfBullets[TableOfBulletsIndex] = newBullet("Normal", MainCharacter, EndOfBulletAim, Weapons[GAMEINV\_EquipedWeapon].DAMAGE)
GameActionLayer:insert(TableOfBullets[TableOfBulletsIndex])
TableOfBulletsIndex = TableOfBulletsIndex + 1
end
end
end
... some more codes
-- Frame listener
Runtime:addEventListener("enterFrame", checkActions)
Stage1DisplayGroup:insert(GameActionLayer)
Stage1DisplayGroup:insert(HUD\_DisplayLayer)
end
On the first run everything is prefect but after Game over or if i pause and retry the stage, i get error. When i try to:
GameActionLayer:insert(TableOfBullets[TableOfBulletsIndex])
the error says: attempt to call method ‘insert’ ( a nil value)
Please what am i doing wrong? Or is this a known bug (which i doubt) [import]uid: 119483 topic_id: 35442 reply_id: 335442[/import]