Where should I place the score object?

In my spgameover.lua file I’ve a display.newText (Line 68) and at line 40 I want to retrieve the score from spstart.lua
Where should I place the score object in the spstart.lua file? In addScore or onLocalCollision, and how do I do that?

spstart.lua:

[code]local storyboard = require “storyboard”
local scene = storyboard.newScene()
local widget = require “widget”
display.setStatusBar( display.HiddenStatusBar )

local background, ball, score, pauseBtn, resumeBtn, leftWall, rightWall, ceiling, floorr, bottom, lock, lock2, scoreText, scoreText2

storyboard.removeScene( “spgameover” )
storyboard.removeScene( “mpstart” )
storyboard.removeScene( “tbmstart” )
storyboard.removeScene( “pmstart” )
storyboard.removeScene( “main” )
storyboard.removeScene( “menu” )
storyboard.removeScene( “sp” )
storyboard.removeScene( “mp” )
storyboard.removeScene( “tbm” )
storyboard.removeScene( “pm” )
storyboard.removeScene( “s” )
storyboard.removeScene( “mpgameover” )
storyboard.removeScene( “tbmgameover” )
storyboard.removeScene( “pmgameover” )

local physics = require( “physics” )
physics.start()
physics.setGravity( 0, 49 )

–physics.setDrawMode(“hybrid”)

require( “ice” )

local scores = ice:loadBox( “scores” )

local function onLocalCollision( self, event )
if event.other.myName == “floor” then
if event.phase == “began” then
local options = { effect = “crossFade”, params={ score = score }}
storyboard.gotoScene( “spgameover”, options )
return true
end
end
end

score = 0

local function addScore( event )
if event.phase == “began” then
score = score + 1
scoreText.text = (score … " ")
end
end

local function removeBottom( event )
if event.phase == “began” then
display.remove( bottom )
end
end

function scene:createScene( event )
local screenGroup = self.view

background = display.newImage ( “road.jpg” )
screenGroup:insert( background )

scoreText = display.newText(score … " ", 0, 0, native.systemFont, 20 )
scoreText.x = 305
scoreText.y = 15
scoreText:setTextColor( 255, 0, 0 )
screenGroup:insert( scoreText )

scoreText2 = display.newText( “Score:”, 0, 0, native.systemFont, 20 )
scoreText2.x = 260
scoreText2.y = 15
scoreText2:setTextColor( 255, 0, 0 )
screenGroup:insert( scoreText2 )

ball = display.newImageRect( “SkySoccer Ball.gif”, 100, 100 )
ball.x = display.contentCenterX
ball.y = 429
ball.myName = “ball”
screenGroup:insert( ball )

pauseBtn = display.newImageRect ( “pausebtn.gif”, 50, 50 )
pauseBtn.x = 20
pauseBtn.y = 20
screenGroup:insert( pauseBtn )

resumeBtn = display.newImageRect ( “resumebtn.gif”, 50, 50 )
resumeBtn.x = 20
resumeBtn.y = 20
resumeBtn.isVisible = false
screenGroup:insert( resumeBtn )

leftWall = display.newRect( -10, 0, 10, display.contentHeight )
leftWall.isVisible = false
screenGroup:insert( leftWall )
rightWall = display.newRect( display.contentWidth, 0, 10, display.contentHeight )
rightWall.isVisible = false
screenGroup:insert( rightWall )
ceiling = display.newRect( 0, -10, display.contentWidth, 10 )
ceiling.isVisible = false
screenGroup:insert( ceiling )
floorr = display.newRect( 0, 479, display.contentWidth, 5 )
floorr.myName = “floor”
floorr.isVisible = false
screenGroup:insert( floorr )
bottom = display.newRect( 0, 466, display.contentWidth, 5 )
bottom.isVisible = false
screenGroup:insert( bottom )

physics.addBody( leftWall, “static”, { bounce = 0.3 } )
physics.addBody( rightWall, “static”, { bounce = 0.3 } )
physics.addBody( ceiling, “static”, { bounce = 0.3 } )

physics.addBody( ball, { bounce = 0, radius = 40, friction = 1.0 } )

physics.addBody( floorr, “dynamic”, { bounce = 0, friction = 10, density = 1 } )

physics.addBody( bottom, “dynamic”, { bounce = 0, friction = 10, density = 1 } )

lock = physics.newJoint( “weld”, leftWall, floorr, floorr.x, floorr.y )
lock2 = physics.newJoint( “weld”, leftWall, bottom, bottom.x, bottom.y )

ball.isFixedRotation = true

ball:addEventListener( “touch”, moveBall )

pauseBtn:addEventListener( “touch”, pauseGame )

resumeBtn:addEventListener( “touch”, resumeGame )

ball.collision = onLocalCollision
ball:addEventListener( “collision”, ball )

ball:addEventListener( “touch”, addScore)

ball:addEventListener( “touch”, removeBottom)

end

function moveBall( event )
if event.phase == “began” then
local x, y = ball.x-event.x, ball.y-event.y
ball:applyLinearImpulse( x / 30, -2, ball.x, ball.y )
return true
end
end

function pauseGame( event )
–if end of touch event
if(event.phase == “ended”) then
–pause the physics
physics.pause()
–pause the ball movement
ball:removeEventListener( “touch”, moveBall )
–make pause button invisible
pauseBtn.isVisible = false
–make resume button visible
resumeBtn.isVisible = true
– indicates successful touch
return true
end
end

function resumeGame( event )
–if end of touch event
if(event.phase == “ended”) then
–resume physics
physics.start()
– resume the ball movement
ball:addEventListener( “touch”, moveBall )
–make pause button visible
pauseBtn.isVisible = true
–make resume button invisible
resumeBtn.isVisible = false
– indicates successful touch
return true
end
end

scene:addEventListener( “createScene”, scene )

return scene[/code]

spgameover.lua:

[code]local storyboard = require “storyboard”
local scene = storyboard.newScene()
local widget = require “widget”
display.setStatusBar( display.HiddenStatusBar )

local background, myText, myButton, myButton2, scoreText, scoreText11, scoreText33, scoreText2, scoreText3, score, params

storyboard.removeScene( “spstart” )
storyboard.removeScene( “mpstart” )
storyboard.removeScene( “tbmstart” )
storyboard.removeScene( “pmstart” )
storyboard.removeScene( “main” )
storyboard.removeScene( “menu” )
storyboard.removeScene( “sp” )
storyboard.removeScene( “mp” )
storyboard.removeScene( “tbm” )
storyboard.removeScene( “pm” )
storyboard.removeScene( “s” )
storyboard.removeScene( “mpgameover” )
storyboard.removeScene( “tbmgameover” )
storyboard.removeScene( “pmgameover” )

require( “ice” )

local scores = ice:loadBox( “scores” )

local function retry( self, event )
local options = { effect = “crossFade” }
storyboard.gotoScene( “spstart”, options )
return true
end

local function menu( self, event )
local options = { effect = “crossFade” }
storyboard.gotoScene( “menu”, options )
return true
end

local onEnterFrame = function ( event )
scoreText2.score.text = scores:retrieve( “scoreText2” ) or 0
end

function scene:createScene( event )
local screenGroup = self.view

params = event.params
score = params.score

background = display.newImage ( “uitlegbg.jpg” )
screenGroup:insert( background )

myText = display.newText( “GAME OVER”, 0, 0, native.systemFont, 40 )
myText.x = display.contentCenterX
myText.y = display.contentWidth / 10
myText:setTextColor( 255, 0, 0 )
screenGroup:insert( myText )

scoreText = display.newText( “Score:”, 50, 120, native.systemFont, 30 )
scoreText:setTextColor( 255, 0, 0 )
screenGroup:insert( scoreText )

scoreText11 = display.newText( “” … score, 250, 120, native.systemFont, 30 )
scoreText11:setTextColor( 255, 0, 0 )
screenGroup:insert( scoreText11 )

scoreText2 = display.newText( “High score:”, 50, 190, native.systemFont, 30 )
scoreText2:setTextColor( 255, 0, 0 )
scoreText2.score = display.newText( “0”, 250, 190, native.systemFont, 30 )
scoreText2.score:setTextColor( 255, 0, 0 )
screenGroup:insert( scoreText2 )

scoreText3 = display.newText( “Total score:”, 50, 260, native.systemFont, 30 )
scoreText3:setTextColor( 255, 0, 0 )
screenGroup:insert( scoreText3 )

scoreText33 = display.newText( “” … score, 250, 260, native.systemFont, 30 )
scoreText33:setTextColor( 255, 0, 0 )
screenGroup:insert( scoreText33 )

myButton = widget.newButton{
left = 15,
top = 415,
default = “retry.png”,
over = “retry2.png”,
onRelease = retry
}
screenGroup:insert( myButton )
myButton2 = widget.newButton{
left = 165,
top = 415,
default = “menu.png”,
over = “menu2.png”,
onRelease = menu
}
screenGroup:insert( myButton2 )

end

scene:addEventListener( “createScene”, scene )

Runtime:addEventListener( “enterFrame”, onEnterFrame )

return scene[/code] [import]uid: 203192 topic_id: 34496 reply_id: 334496[/import]

Hi @borisbroekie,
I’m not sure I see the issue here… it appears that you’re properly passing the score value from “spstart” to “spgameover” in the params table of the “gotoScene()” function. Then, in “spgameover” in the “createScene()” function, you’re reading that value from the “event.params” argument. So, I don’t follow what your intention is… can you please be more specific?

Thanks,
Brent [import]uid: 200026 topic_id: 34496 reply_id: 137183[/import]

Can you look at this?

http://developer.coronalabs.com/forum/2013/01/04/whats-wrong-code [import]uid: 203192 topic_id: 34496 reply_id: 137374[/import]

Hi @borisbroekie,
I’m not sure I see the issue here… it appears that you’re properly passing the score value from “spstart” to “spgameover” in the params table of the “gotoScene()” function. Then, in “spgameover” in the “createScene()” function, you’re reading that value from the “event.params” argument. So, I don’t follow what your intention is… can you please be more specific?

Thanks,
Brent [import]uid: 200026 topic_id: 34496 reply_id: 137183[/import]

Can you look at this?

http://developer.coronalabs.com/forum/2013/01/04/whats-wrong-code [import]uid: 203192 topic_id: 34496 reply_id: 137374[/import]