Who doesn't like some friendly competition? We're familiar with scoreboards from the games we made in the previous chapters. So, we are not strangers to tracking the score. Perform the following steps to set the score:
Create a local function called
setScore()
with a parameter calledscoreNum
:local setScore = function( scoreNum )
Set the variables to count the score:
local newScore = scoreNum gameScore = newScore if gameScore < 0 then gameScore = 0; end
Have the score updated when points are earned in game play and close the function:
scoreText.text = "Score: " .. gameScore scoreText.xScale = 0.5; scoreText.yScale = 0.5 scoreText.x = (scoreText.contentWidth * 0.5) + 15 scoreText.y = 15 end