Scoring error

i’ve got the score to show up but it doesnt count when the fruit is hit

[code]
function shootObject(type)
local object = type == “fruit” and getRandomFruit() or getBomb()

fruitGroup:insert(object)

object.x = display.contentWidth / 2
object.y = display.contentHeight + object.height * 2

fruitProp.radius = object.height / 5
physics.addBody(object, “dynamic”, fruitProp)

if(type == “fruit”) then
object:addEventListener(“touch”, function(event) chopFruit(object) getScore() scorePoint() end)

else
local bombTouchFunction
bombTouchFunction = function(event) explodeBomb(object, bombTouchFunction); end
object:addEventListener(“touch”, bombTouchFunction)

end
local getScore()
local scoreDisplay = display.newText( ("Score " … playerPoints), 0, 0, “ArialRoundedMTBold”, 30 )
scoreDisplay.x = display.contentWidth / 2 + 230
scoreDisplay.y = display.contentHeight / 2 - 50
scoreDisplay:setTextColor( 255,255,255 )
group:insert(scoreDisplay)
[/code] [import]uid: 74663 topic_id: 12636 reply_id: 312636[/import]

Where is “scorePoint” defined? I can’t see it in your code.

Also, it would make sense to have the score code above the code where you’re spawning things, IMHO. [import]uid: 52491 topic_id: 12636 reply_id: 46224[/import]

I see a lot of things that confuse me with that code.

What is “local getScore()”?

Are the lines of code below it only being called once?

That anonymous function in the event listener: doesn’t that need to be in a enclosure?

Any way, assuming that the

 local scoreDisplay = display.newText( ("Score " .. playerPoints), 0, 0, "ArialRoundedMTBold", 30 )  
scoreDisplay.x = display.contentWidth / 2 + 230  
scoreDisplay.y = display.contentHeight / 2 - 50  
scoreDisplay:setTextColor( 255,255,255 )  
group:insert(scoreDisplay)  

is all part of a function getScore() and that function is being called on the object Touch event listener, then you are leaking memory by creating scoreDisplay every time that function is called and never disposing it.

Typically you will have a function that setups up the display and is called once:

local function initScoreBoard()  
 local scoreDisplay = display.newText( "0", 0, 0, "ArialRoundedMTBold", 30 )  
 scoreDisplay.x = display.contentWidth / 2 + 230  
 scoreDisplay.y = display.contentHeight / 2 - 50  
 scoreDisplay:setTextColor( 255,255,255 )  
 group:insert(scoreDisplay)  
end  

then later when you want to change the score:

...  
score = score + 1  
scoreDisplay.text = string.format("%d",score)  
...  

And the underlying Corona SDK engine will update the score.
[import]uid: 19626 topic_id: 12636 reply_id: 46273[/import]