Remove an Object in Function

What I’m trying to do is remove balloon when I change scene heres what I mean.

  
-- This function is repeated 7 times with variable not changed  
local group = display.newGroup()  
  
local spawnBalloon = function()  
if spawn == true then  
ball = display.newImage( group, "balloon.png" )  
ball.x = 60 + math.random( 160 )  
ball.y = 550  
physics.addBody( ball, { density=0.0, friction=0.1, bounce=0.1 } )  
ball:addEventListener( "touch", spawnBall )  
balls[#balls + 1] = ball  
ball.name = "ball"  
end  
end  
timer.performWithDelay(500, ball, -1)  
  
local function delete()  
for i=group.numChildren,1,-1 do  
 local child = group[i]  
if group[i].y \< -100 then  
display.remove(group[i]) -- dont know about this part, try it  
end  
end  
end  
   
Runtime:addEventListener("enterFrame", delete)  
  
-- This function is the quit which is suppose to change scene  
local function quit (event)  
if event.phase == "ended" then  
director:changeScene ("play")  
bkg:removeSelf()  
Quit.isVisible = false  
Resume.isVisible = false  
Pause.isVisible = false  
end  
end  
Quit:addEventListener ("touch", quit)  
  

What I’m trying to do is remove the balloons when I change the scene to next scene. Every time I change I see balloons in the next scene. Also when I put localGroup:insert(ball) I would get an error. So can any body help me figure out this problem. [import]uid: 17058 topic_id: 19334 reply_id: 319334[/import]

hey, i’d help you, but you it seems that you wont appreciate my or other one’s help, so… use search on forums, there’s all you need, you clearly dont understand how director module works, study all things here: learningcorona.com [import]uid: 16142 topic_id: 19334 reply_id: 74590[/import]

@darkconsoles I do know about director module is just there was a simple mistake I had found. Is I’m really slow at times finding my mistakes. Thanks for showing me the website. Also sorry again. Have a nice day. :slight_smile: [import]uid: 17058 topic_id: 19334 reply_id: 74599[/import]

@darkconsoles I do appreciate your help from all the examples you showed they all worked I thank you. I’m sorry of not appreciating. I’m really grateful that every one in the forums helping me I feel so happy when I get the help and I understand the help. I promise I’ll be grateful. [import]uid: 17058 topic_id: 19334 reply_id: 74592[/import]

Hey, sorry, just to clarify - you have fixed this now?

Peach :slight_smile: [import]uid: 52491 topic_id: 19334 reply_id: 74627[/import]

I’m confused.
Firstly, where in your code are you trying to remove the ball objects? The only place I can see it is in the delete function, but that is a function which deletes based on screen position.
Second, are you trying to delete the objects after the scene change, rather than before? [import]uid: 84115 topic_id: 19334 reply_id: 74653[/import]

@Peach yeah I have fix this is not in this code is was actually in the beginning of my code page and the end. Just simple mistake I didn’t know. [import]uid: 17058 topic_id: 19334 reply_id: 74658[/import]