"GDevelop 5: High Score Increases Incorrectly After Restart"

Issue Description:
I’m developing a Flappy Bird-like game in GDevelop 5. The game functions as expected during the initial playthrough:
Upon the bird’s death, the end screen displays both the current score and the high score accurately.
However, after clicking the restart button:
The game restarts, and while the current score resets correctly, the high score increments incorrectly.
Example Scenario:
First Playthrough:
Achieved Score: 5
Displayed High Score: 5
After Restart:
Achieved Score: 3
Displayed High Score: 6 (instead of remaining 5)
Observations:
I’ve noticed that altering the order of events in the event sheet affects the high score behavior. For instance, certain configurations result in the high score increasing by 2, while others cause it to display as 0. This suggests that the sequence of events might be contributing to the problem.
Request for Assistance:
I’m seeking guidance on how to correctly manage and display the high score upon restarting the game. Any insights into the proper ordering of events or best practices for handling score variables in GDevelop 5 would be greatly appreciated.

1 Like

Hi,
When you press the space key, the score increases. If the score surpasses the current high score, the new high score is saved in internal storage. This means that even if you quit the game and restart it later, the high score remains saved, unless you delete the storage. However, the regular score resets to zero every time you start the game.

thanks for replying to me, i just left this project but i immediately thought if anyone have replied to me, so ok i think u didnt understand my problem correctly, my problem is that whenever i play game lets say i scored 6 ok, but when i click on play again and dies on 3 so it should update highscore right cause i didnt score more than 6 but the highscore chages to 7 or even 8, that is my problem the highscore issue u can see all of my ss up there, if u have any time so can u fix my game completely ill be soo thankful, if u can come to discord itz_umer7

Hi,

I noticed a potential syntax issue in your code that might prevent it from executing correctly. The “Trigger Once” condition appears to be placed before the actual score comparison. It should be moved after the condition.

Regarding your high score problem:

Have you had a chance to try my suggested solution? It’s designed to update the high score only when a new best score is achieved, and then use that value as a reference. Based on your description, it should address the issue of the high score incorrectly increasing.

First of all, declare your variables.

Second, the most glaring problem is that you are treating the variable Highscore as a number in one place, and as a string in another. When you check if score is greater than Highscore, and save/load it, you are using a number variable. But then at the end when you display it, you’re using VariableString:

SubStr(VariableString(score [not a string]), 0, StrLength(VariableString(score)) - 2)

I don’t understand why you are using things like SubStr here. I imagine it should be:

text of score2 set to “SCORE=” + score
text of HIGHSCORE set to “HIGHSCORE=” + Highscore

In this case Gdevelop will automatically convert the numbers to a string for concatenation. When you need to manually convert a number, use ToString(score).

The SubStr part is really a mystery to me, even if those were strings it wouldn’t make sense. Let’s say the score variable was a string with “100”. You have:

SubStr(score, 0, StrLength(score) - 2)

This says, take the piece of “100” starting from position 0, going to the position at (end - 2):

SubStr(“100”, 0, 3 - 2)
or
SubStr(“100”, 0, 1)

In other words, it’s getting the characters from position 0 to position 1. Which is only the first character (the end point is exclusive). So putting in “100” the result would be:

“SCORE=1”

1 Like