Developing a Game with Corona SDK, Second Steps

Hello! Today’s post is going to be shorter than usual, but it’s a vital part of developing our game with Corona SDK! If you would like to see the previous post on this topic, please visit the Corona SDK tutorials menu item or go to the previous post here.

In the previous post, we covered how to add a coin to the screen and how to make the player ‘grab’ the coin. Today, we are going to track how many times the player caught a coin by adding a simple scoring system to the game. We do this by setting up a score variable to track the number of scores and we set up a text display object to show the player the score. Here’s the code.

-- On line 15, add the variable score
score = 0; -- Set Score to 0

-- On line 63 to 65, add the following lines
-- Add Score to Screen
local playerScore = display.newText("Score: "..score, 0, 0, native.systemFont, 16);
playerScore:setTextColor(0, 0, 0);

Next, we will add the scoring functionality. Everytime the player collides with the coin, we want to add 1 point to the score variable and update the text display object with the latest score. Here’s how.

-- Add the following to Line 122
score = score + 1;
playerScore.text = "Score: " .. score

And that’s it! We’ve added a simple scoring system to our game. If you would like to see more tutorials, please leave a comment. This helps keep me motivated to continue to bring high quality tutorials to your site. As always, you can download the full source below. As always, you can download the full source below.

Download Source Code


8 Comments
  1. Hi, I have an issue. The counter’s working, but the previous numbers aren’t deleting. As in, they keep building on top of each other making it unreadable. Any idea how to fix this?

  2. The score shows up but it dosen’t change when it hits my net.

  3. Is there a specific place to put it

  4. Hello,

    I was wondering if you had any code for when the score hits a certain number and helps transition into another screen. For example if the score hits 30, it goes to another screen and says ‘congratulations you won’.

    Hopefully this makes sense, thank you if you reply.

    • To make this happen, you would need to keep track of a variable in your game and when that variable hits a certain numbers, you’ll need to call storyboard.goToScene().

  5. is it possible to put dots to score like this 100.000.000 or spaces 100 000 000
    so it wouldn’t be like this 100000000

    • Sure! You could just write an if/then statement or a function that will prep the score for you.

Leave a Reply