Need help insert object

I still need help in Inserting object properly here is the code example

[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]

Ok what I need help is in the section of the balloon where they are called groups. I want to know when I change scene like when times up how would I insert the balloons so they won’t appear in the next. Help needed. Appreciated if I got help just please I need help I’ve been stress trying to figure this out myself. Sorry If I’m bothering with the related forums [import]uid: 17058 topic_id: 19377 reply_id: 319377[/import]

Change [lua]group:insert(ball)[/lua] to [lua]localGroup:insert(ball)[/lua] - that should do it I believe.

Let me know.

Peach :slight_smile: [import]uid: 52491 topic_id: 19377 reply_id: 74836[/import]

@peach when I do localGroup:insert(ball) I get this error you see in the see in the code when I put the time has tick 10 times change scene. When the game change scene based on the time I get the error but when I change scene when I click quit it works. So 50% of my problem is solved what could be the problem of the error appearing when the balloon changes scene based on time [import]uid: 17058 topic_id: 19377 reply_id: 74868[/import]

If you put up some plug and play someone may be able to run through it for you and spend some of their time trying to debug.

They can’t do it with this code as it requires images they don’t have.

(You could also upload a zip of the project and provide a link.)

Peach :slight_smile: [import]uid: 52491 topic_id: 19377 reply_id: 74873[/import]

@Peach ok here’s the link for the project

http://tinylemongames.yolasite.com/twitter-news.php

you should see it under the twitter news the file is called minigames. The lua file I’m struggling is call balloon popper.lua [import]uid: 17058 topic_id: 19377 reply_id: 74898[/import]

@Peach thanks for your help a lot I really appreciate it. Sorry for the trouble I caused and also sorry forum.

But thanks alot. :slight_smile: [import]uid: 17058 topic_id: 19377 reply_id: 74907[/import]

I assume that means my email helped, I’m glad.

It’s all OK either way :slight_smile:

Peach [import]uid: 52491 topic_id: 19377 reply_id: 75001[/import]