Count the coins in your game
ReadingKeeping count
Now put a counting script into your own game. It counts the coins on level 1 and cheers the player on.
How to read it
| Lines | What they do |
|---|---|
when any {Heroes} enters and @coins is 0 | When the level starts, the count is set to 0 |
when any {Heroes} collects a coin | This rule runs for each coin |
@coins goes up by 1 | Adds 1 to the count |
@left is 30 - @coins | Works out how many are left |
if @left is 15 | Halfway: half of 30 is 15 |
if @left is 0 | None left: every coin is found |
Give it to your level
- Press Copy, at the bottom of the script in the code box above.
- Open your game in the builder below, on level 1.
- Press the Map button
, under the map. - At the bottom of the level's settings, press Level script.
- Press Code
, and paste the script in. Press Save
.
Try it
Press Play
and collect your coins. A banner shows when you are halfway, and again when you have them all.
Make it fit your level
The script has two numbers that depend on your total: 30 and 15. If your level has a different total, change both.
| Your total | Halfway | The sum |
|---|---|---|
| 30 | 15 | 30 ÷ 2 |
| 24 | 12 | 24 ÷ 2 |
| 40 | 20 | 40 ÷ 2 |

