Well, this may be a bit advanced for you, but this is how I handle score keeping (sometimes)
-- -- This is not great, but it it totally functional. My method really has more parts, but this -- is a simplification which you can expand upon later. -- local scoreLabel = display.newText( "Score: 0", display.contentCenterX, 100 ) scoreLabel.value = 0 function scoreLabel.onScore( self, event ) if( event.value ) then self.value = self.value + event.value score.text = "Score: " .. tostring( self.value ) end end Runtime:addEventListener( "onScore", scoreLabel ) function scoreLabel.finalize( self ) Runtime:removeEventListener("onScore",self) end scoreLabel:addEventListener("finalize")
Now, at a later date I can do this ANYWHERE and the score will ‘auto-update’
local circle = display.newCircle( 100, 100, 100 ) function circle.touch( self, event ) if( event.phase == "ended" ) then Runtime:dispatchEvent( { name = "onScore", value = math.random(1,5) } ) end end circle:addEventListener("touch")
Tapping the circle adds to our score and the label auto-updates.
CODE MAY CONTAIN TYPOS