Reader small image

You're reading from  Corona SDK Mobile Game Development: Beginner's Guide

Product typeBook
Published inMar 2015
Publisher
ISBN-139781783559343
Edition1st Edition
Tools
Right arrow
Author (1)
Michelle M Fernandez
Michelle M Fernandez
Right arrow

Time for action – setting the score


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:

  1. Create a local function called setScore() with a parameter called scoreNum:

        local setScore = function( scoreNum )
  2. Set the variables to count the score:

          local newScore = scoreNum
          gameScore = newScore
          if gameScore < 0 then gameScore = 0; end
  3. 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

What just happened?

When setScore(scoreNum) is called within any function, it will refer to all the methods using the gameScore variable. Assuming gameScore = 0 at the start of the application, the value increments to what...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Corona SDK Mobile Game Development: Beginner's Guide
Published in: Mar 2015Publisher: ISBN-13: 9781783559343

Author (1)