Skip to main content

Tutorial 2: Keep score and win

Your game has one coin. Now you will add more, count them with a Score variable, show the score on a label, and show “You win!” when all are collected.

Do it in the app

At the end of Tutorial 1 tap Continue to part 2, or on the home screen tap New here? Make your first game → Part 2 (it starts from a finished Part 1).

Part 2 starts
Part 2 starts
1More coins

In the Objects tab tap ⋮ next to the coin and choose Duplicate. Do it until you have 3 coins.

Tap ⋮ next to the coin
Tap ⋮ next to the coin
Duplicate
Duplicate

Copies share the same name, so they are all instances of the same object type — one event works for all of them.

2Spread them out

The copies sit on top of each other. Tap each coin (in the 3D view or in the Objects list) and drag its arrows so the coins are spread around the arena. You can also type a Position in the Inspect tab.

tut2 04 spread
3A label for the score

Labels show text on the screen. In Objects tap + Add and choose Label (under UI (on screen)). Then, in Inspect, change its Text to Score: 0.

+ Add → Label
+ Add → Label
Text: Score: 0
Text: Score: 0

When a UI element is selected, the 3D view switches to UI mode and shows the game screen as a frame. See Game UI.

4Count the coins

Open Logic → Main events. Under your collision event tap Add action → System → Add to variable. Variables remember numbers while the game runs. Choose Score (if it isn’t there, pick + New variable… and name it Score), keep Value at 1, and tap ✓ Add action.

Add action
Add action
System actions
System actions
New variable: Score
New variable: Score
Add 1 to Score
Add 1 to Score
5Show the score

Tap Add action again, pick Label, then Set label. As the text type

"Score: " + Score

with the quotes around Score: . Text in quotes is shown as it is; Score without quotes is the variable’s value. Tap ✓ Add action.

Add action → Label
Add action → Label
Set label to the score
Set label to the score
6WHEN all coins are collected…

Tap + Add event → System → Compare variable. Choose Score, keep =, set Value to 3 (your number of coins) and tap ✓ Add condition.

+ Add event
+ Add event
Score = 3
Score = 3
7…DO show “You win!”

Under that new event tap Add action, pick Label, Set label, type "You win!" (with the quotes) and tap ✓ Add action. Your sheet now has two events:

The finished event sheet
The finished event sheet
  1. WHEN Player collides with Cylinder → destroy that coin, add 1 to Score, show the score.
  2. WHEN Score = 3 → show “You win!”.

Only the coin the ball touched is destroyed, not all of them: the collision condition picks that coin, and actions only apply to picked instances. See How events work.

8Collect them all

Go back, tap ▶ Play and collect all the coins. Watch the score go up, then “You win!”.

Playing
Playing
🎉 You finished the tutorials!
🎉 You finished the tutorials!

What next?​

  • Add a sound when a coin is collected: Audio → Play sound (see Sound).
  • Add a timer: Time → Start timer and On timer finished (see Advanced events).
  • Add a second level: a new scene and Go to scene (see Scenes).
  • Open the Roll-a-ball: Coin collector template: it has a start menu, a coin bar, a pause button and a win screen (see Templates).