Objects being inserted

Sorry for being a bother for this question about insert object. Ok my problem is when I do group:insert(ball) on the object ball That object would appear in the next scene. Here is the code to clarify things better.

[code] module(…, package.seeall)

function new()
local localGroup = display.newGroup()

require( “ice” )
local physics = require(“physics”)
local ui = require(“ui”)
local gameUI = require(“gameUI”)
physics.start()
physics.setGravity(0, -1)
local scores = ice:loadBox( “scores” )

local high = scores:retrieve(“best”)
print(high)

display.setStatusBar( display.HiddenStatusBar )

local scoreText
local score = 0
local highscore
local button1
local runMode = true
local spawn = true
local touch = true
local gameOver = false
local bkg = display.newImage( “bkg.png” )
bkg.x = 160; bkg.y = 240
localGroup:insert(bkg)

local score_txt =display.newText("Score: ",0,0,nil,25)
score_txt.x = 160; score_txt.y = 440
score_txt:setTextColor(0,0,0)
score_txt.text = "Score: "… score
localGroup:insert(score_txt)

local spawnBall = function( event )
local t = event.target
local phase = event.phase
if touch == true then
if “began” == phase then
t:removeSelf() – destroy object
score = score + math.random( 1000 )
score_txt.text = "Score: "… score
end
– Stop further propagation of touch event
return true
end
end

local balls = {}

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
group:insert(ball)
end
end
timer.performWithDelay(500, spawnBalloon, -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)
local bt = display.newImage (“pause.png”)
bt.x = 290
bt.y = 30
localGroup:insert(bt)

local bt2 = display.newImage (“pauseOver.png”)
bt2.x = bt.x
bt2.y = bt.y
bt2.isVisible = false
localGroup:insert(bt2)

local Pause = display.newText(“Pause”, 5, 0, “ArialRoundedMTBold”, 30)
Pause.x = 160
Pause.y = 110
Pause:setTextColor(0,0,0)
Pause.isVisible = false
localGroup:insert(Pause)

local Resume = display.newText(“Resume”, 5, 0, “ArialRoundedMTBold”, 25)
Resume.x = 160
Resume.y = 190
Resume:setTextColor(0,0,0)
Resume.isVisible = false
localGroup:insert(Resume)

local Quit = display.newText(“Quit”, 5, 0, “ArialRoundedMTBold”, 25)
Quit.x = 160
Quit.y = 270
Quit:setTextColor(0,0,0)
Quit.isVisible = false
localGroup:insert(Quit)

–Function for start button
local function done ()
physics.pause()
spawn = false
touch = false
bt.isVisible = false
bt2.isVisible = true
Quit.isVisible = true
Resume.isVisible = true
Pause.isVisible = true
result = timer.pause( timerID )
end
bt:addEventListener(“tap”, done)

–Function for pause button
local function done ()
physics.start()
spawn = true
touch = true
bt.isVisible = true
bt2.isVisible = false
Quit.isVisible = false
Resume.isVisible = false
Pause.isVisible = false
result = timer.resume( timerID )
end
Resume:addEventListener(“tap”, done)

local function quit (event)
if event.phase == “ended” then
director:changeScene (“play”)
Quit.isVisible = false
Resume.isVisible = false
Pause.isVisible = false
spawn = false
end
end
Quit:addEventListener (“touch”, quit)

local count = 60
local hasRun = 0

local time = display.newText( “60”, 5, 0, “ArialRoundedMTBold”, 40)
time:setTextColor( 0, 0, 0 )
localGroup:insert(time)

local timeDelay = 700

function time:timer( event )

count = count-1
hasRun = hasRun+1

self.text = count

if hasRun >= 10 then
timer.cancel( event.source )
director:changeScene (“popover”)
end
end

– Register to call t’s timer method 50 times
timerID = timer.performWithDelay( timeDelay, time, -1 )

local highText = display.newText("", 0,0,nil,30)
highText.x = display.contentWidth/2
highText.y = display.contentHeight/2
highText.text = "HighScore: "… scores:retrieve(“best”)
localGroup:insert(highText)

local function show_highScore()
gameOver = not gameOver

scores:storeIfHigher( “best”, score )
scores:save()
local highText = display.newText("", 0,0,nil,30)
highText.x = display.contentWidth/2
highText.y = display.contentHeight/2
if score > high then
highText.text = "HighScore: "… scores:retrieve(“best”)
else

if score > high then
print(“new high score”)
highText.text = "HighScore: "… scores:retrieve(“best”)
end
end

end

timer.performWithDelay(60000, show_highScore, 1)

return localGroup
end[/code]

Now you should see that I did group:insert(ball) and when I did that the balloon appeared in the next scene. I appreciate the help, and also sorry for being a bother. [import]uid: 17058 topic_id: 19368 reply_id: 319368[/import]

Sorry for being impatient but can I get some help please I would appreciate.

Sorry again [import]uid: 17058 topic_id: 19368 reply_id: 74768[/import]

localGroup:insert(group)

(as your inserting most things in group but not clearing “group” upon changing scenes. [import]uid: 84637 topic_id: 19368 reply_id: 74775[/import]

@Danny so I would put localGroup:insert(group) were my object is right
[import]uid: 17058 topic_id: 19368 reply_id: 74776[/import]

@Danny so clear things in “group” upon changing scene can you please clarify a little more [import]uid: 17058 topic_id: 19368 reply_id: 74778[/import]

like this :

group = display.newGroup()  
localGroup:insert(group)  

Doing it that way, everything in group will be removed from the stage at least. You will probably still want to follow the usual guidelines of nil’ing out your variables etc [import]uid: 84637 topic_id: 19368 reply_id: 74779[/import]

@Danny I did your example and I keep getting an error. What I did was place localGroup:insert(group) under my balloon function then I placed it on the function of groups being removed on certain stage height and still nothing I know I’m doing something wrong. Sorry for giving a hard time [import]uid: 17058 topic_id: 19368 reply_id: 74782[/import]

Can you post up some more code please [import]uid: 84637 topic_id: 19368 reply_id: 74785[/import]

@Danny this is the only codes that I’m struggling I need help figuring out the section of the code where I’m trying to insert group but I keep getting an error. [import]uid: 17058 topic_id: 19368 reply_id: 74789[/import]