Who doesn't like some friendly competition? We're familiar with scoreboards from the games we've made in the previous chapters. So we are no strangers on how to track the score.
Create a local function called
setScore()
with a parameter calledscoreNum
.local setScore = function( scoreNum )
Set 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 gameplay 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