spawning objects not removing after leaving scene

Hi my objects are not removing after leaving the scene, i have tried to purging and removing the scene, but the objects will just keep on spawning in a other scene? 

local badclout1 = {}  local bad1Group = display.newGroup() local function spawnBC1()    local badclouts1 = display.newImage("BCloud1.png")    badclouts1.x = math.random(0, \_W)    physics.addBody( badclouts1, "dynamic", { density=.1, bounce=.1, friction=.2, radius=45 } )           badclouts1.name = "BCloud1"     badclouts1.bodyType = "kinematic"    badclouts1.isSensor = true    badclouts1.y = math.random(-100, -50)    badclouts1.index = #badclout1 + 1    bad1Group:insert(badclouts1)    badclouts1.rotation = math.random(-10,10) -- Rotate the object    badclouts1:setLinearVelocity(0, math.random(speeda1, speedb1)) -- Drop down    badclout1[badclouts1.index] = badclouts1    tmrSpawn1 = timer.performWithDelay(math.random(spawna, spawnb), spawnBC1) return badclouts1  end tmrSpawn1 = timer.performWithDelay(math.random(1000, 10000), spawnBC1)  local function removeBomb()   for i, v in pairs(badclout1) do     if badclout1[i].y \>1000 then         badclout1[i]:removeSelf()         badclout1[i] = nil      end   end end Runtime:addEventListener("enterFrame", removeBomb)  

 is there something in my code that keeps it on the screen ?

If you are using Storyboard you must put all display objects in a group like so:

group:insert(badclouts1)

instead of:

 bad1Group:insert(badclouts1)

Hi when i change it i get this error : 

2013-06-24 19:30:49.824 Corona Simulator[307:707] Runtime error /Users/macuser/Desktop/spawn/game.lua:65: attempt to compare number with nil stack traceback: &nbsp;&nbsp;&nbsp;&nbsp;[C]: ? &nbsp;&nbsp;&nbsp;&nbsp;/Users/macuser/Desktop/spawn/game.lua:65: in function \</Users/macuser/Desktop/spawn/game.lua:63\> &nbsp;&nbsp;&nbsp;&nbsp;?: in function \<?:218\>

the code:

63 local function removeBomb() 64 for i, v in pairs(backgroundclouts) do 65 &nbsp; if backgroundclouts[i].y \>1000 then 66 &nbsp; &nbsp; &nbsp; backgroundclouts[i]:removeSelf() 67 &nbsp; &nbsp; &nbsp; backgroundclouts[i] = nil 68 &nbsp; &nbsp;end 69 end 70 end 80 Runtime:addEventListener("enterFrame", removeBomb) &nbsp;

try:

if backgroundclouts[i].y and backgroundclouts[i].y >1000 then

It sounds like you’re checking for a backgroundclouts[] that doesn’t have a y member.

oky so that fixes the error now when i use group:insert(backclouts) (<- line 53) i get this error (on collision ): 

Attempt to call method 'insert' (a nil value) stack traceback: &nbsp;&nbsp;&nbsp;&nbsp;[C]: in function 'insert' &nbsp;&nbsp;&nbsp;&nbsp;/Users/macuser/Desktop/spawn/game.lua:53: in function '\_listener' &nbsp;&nbsp;&nbsp;&nbsp;?: in function \<?:141\> &nbsp;&nbsp;&nbsp;&nbsp;?: in function \<?:218\> &nbsp;

I don’t see you using backclouts anywhere in your code above.  Are you talking about backgroundclouts?  If so, that’s a table and you have to insert the member into the group, not the whole table: 

    group:insert(backgroundclouts[i])

or something like that.  Perhaps if you posted more of your code, we could do a bit more than speculate.

im using timer.cancel and rewritten the game’s storyboard it seams the behave now :smiley:  

If you are using Storyboard you must put all display objects in a group like so:

group:insert(badclouts1)

instead of:

 bad1Group:insert(badclouts1)

Hi when i change it i get this error : 

2013-06-24 19:30:49.824 Corona Simulator[307:707] Runtime error /Users/macuser/Desktop/spawn/game.lua:65: attempt to compare number with nil stack traceback: &nbsp;&nbsp;&nbsp;&nbsp;[C]: ? &nbsp;&nbsp;&nbsp;&nbsp;/Users/macuser/Desktop/spawn/game.lua:65: in function \</Users/macuser/Desktop/spawn/game.lua:63\> &nbsp;&nbsp;&nbsp;&nbsp;?: in function \<?:218\>

the code:

63 local function removeBomb() 64 for i, v in pairs(backgroundclouts) do 65 &nbsp; if backgroundclouts[i].y \>1000 then 66 &nbsp; &nbsp; &nbsp; backgroundclouts[i]:removeSelf() 67 &nbsp; &nbsp; &nbsp; backgroundclouts[i] = nil 68 &nbsp; &nbsp;end 69 end 70 end 80 Runtime:addEventListener("enterFrame", removeBomb) &nbsp;

try:

if backgroundclouts[i].y and backgroundclouts[i].y >1000 then

It sounds like you’re checking for a backgroundclouts[] that doesn’t have a y member.

oky so that fixes the error now when i use group:insert(backclouts) (<- line 53) i get this error (on collision ): 

Attempt to call method 'insert' (a nil value) stack traceback: &nbsp;&nbsp;&nbsp;&nbsp;[C]: in function 'insert' &nbsp;&nbsp;&nbsp;&nbsp;/Users/macuser/Desktop/spawn/game.lua:53: in function '\_listener' &nbsp;&nbsp;&nbsp;&nbsp;?: in function \<?:141\> &nbsp;&nbsp;&nbsp;&nbsp;?: in function \<?:218\> &nbsp;

I don’t see you using backclouts anywhere in your code above.  Are you talking about backgroundclouts?  If so, that’s a table and you have to insert the member into the group, not the whole table: 

    group:insert(backgroundclouts[i])

or something like that.  Perhaps if you posted more of your code, we could do a bit more than speculate.

im using timer.cancel and rewritten the game’s storyboard it seams the behave now :smiley: