Adding up variables to make a high score

In my game, the player has a score at the end of each level (each set as a global variable). When they finish the last level, their final score pops up, an addition of all the scores. But I don’t know how to do it.

The way id make it is with 2 Global Variables…

1 for Current Score
1 for Total Score

The easy way to do this is… Every time you add the score to the “Current Score” variable, you also add to “Total Score”.

At the end of the level you can display both.

The “Current Score” you can reset after each level, but the “Total Score” you only reset if the player restarts the game.

Does that make sense?

1 Like

You have 2 variables
1 is score for current level let’s say LevelScore
2 is TotalScore

All you need to do is display both at the end of level
Change value of global variable TotalScore Add GlobalVariable(LevelScore)
Tirigger once

Change text of text object
Set to "Level Score “+ToString(GlobalVariable(LevelScore))+” Total Score "+ToString(GlobalVariable(LevelScore)+GlobalVariable(TotalScore))

And you repeat process for every level
Although maybe LevelScore should be scene variable if you are changing scenes and not resetting same scene over and over
Or at beginning of scene you Set LevelScore to 0
Choice is yours

That’s the only part of your solution I wouldn’t recommend. Add the current score to the level only when the level is completed. Otherwise “Total Score” accumulates failed scores too.

Well yeah… its a score, your suposed to add everything, even if you dont clear the level.

I supose it depends on the game really, but since hes talking about clearing levels and displaying a highscore at the end, im thinking Arcade style, with player lives…

If thats the case, you add both.
If you have infinite lives, then yeah, add at the end.

When i hear High Score or Total Score i always think Arcade :slight_smile: