Putting score on different scene

Hi,
I used the tutorial to pause and switch scenes, which works well, but I can’t figure out how to put the score on the start scene as well as the game scene, as the scenes switch so quickly you can’t see what your score was.
Any help would be appreciated.
Thanks, Dave :slight_smile:

If you want to share the score between each scene, make sure you are using Global variable to store the score. In case you want the score to be independent for each scene, make sure you are using Scene variable to store the score.

Global variables can be accessed from any scene through the whole game and remain in memory as long the game is running.

Scene variables can be accessed from the current scene only and it value is dropped when you change the scene except you pause the scene, in that case I guess the variable remain in memory but you still can’t access it from the other scenes.

If you want something to be shared between scenes, store it in Global variables, if you don’t want something to be shared between scenes, store it in scene variables.
Also, if you don’t want to share something between objects in your scene, you can use Object variables. For example if you want to store health for each enemy individually. Object variables exists individually for each object and remain in memory as long an object exists.

No luck getting the other score to work yet with global, I’ll keep trying different things,
Thanks for your help :slight_smile:

If you are trying to share and use the score globally in your game there is not many options really.
Other thing you can try to write the score in to file (web storage in HTML5) before change the scene, and read the score from the file (web storage) at the beginning of each scene. But Global variable should work.

“getting the other score” makes me wonder what you really trying to do. If you want to have a score individually for each scene and you want to add the score of each scene to a global score at the end, you need to use both scene and global variable. Use scene variable to store the score of the current scene and before change the scene, add the score from the scene variable to the global. But feel free to share more details about your problem and what you trying to do if you get stuck.

Yes I was a bit vague, there are just 2 scenes, the game scene and the start scene with the start button on it.
When the game is over and it switches to start screen, I want the score that I got in the game to be on the start screen, as I’m not doing a high score, mainly because I couldn’t find a tutorial for it.
I followed the score tutorial on YouTube, using global variable instead of scene. But doing the same as it said in the tutorial.

In events I have tried just global, then both scene and global, but nothing happened except for one time, when the game score started at the score of the previous game instead of zero.
I don’t know how to add the score from the scene variable to the global.
I’m very new to gdevelop.
Do I have to make a text object for score on start scene, or just copy n paste the one on the game scene? And do I set both score text objects as global objects.
Thanks.

I don’t have a chance to test it but I try to explain without errors, in case it doesn’t work for you or you don’t understand something just ask.

To display a score you going to need a text object and for the text you need to use this expression to display the value of a variable

display Global variable

"" + ToString(GlobalVariable(variable_name))

display Scene variable

"" + ToString(Variable(variable_name))

Just replace variable_name with the name of your variable.

Let say, you have a global variable called GlobalScore. You going to use this variable to display the score in the start scene.
So create a text object and as text use the expression as follow:

"" + ToString(GlobalVariable(GlobalScore))

Do not type this expression simply as text in object properties but you need to add an action using events to set the text of the text object and in the event properties you need to use this expression for text. You should find the action to set the text of a text object in the event list.

At the very first time it should display 0 since the variable in the expression should return 0 and the text object should display 0.

It fine, you don’t need to do anything else, you don’t need to create the variable or set it value in the start scene just use the above expression as text for the text object through an event.

Next, go to the game scene and do the same with the a text object but this time use a scene variable which is called SceneScore

"" + ToString(Variable(SceneScore))

Obviously, when you do score in the game, use this variable.

Finally, before you change the game scene back to the start scene, add the value of SceneScore to the GlobalScore variable using this expression as value:

Variable(SceneScore)

Basically, what you need to do is add the value of SceneScore to GlobalScore.
GlobalScore = GlobalScore + SceneScore and the event should looks like this:

Do + Variable(SceneScore) to the value of GlobalScore
You can find the action to set the value of the variable in the event list.

After, when you go back to the start scene, it should display the score you just made in the game scene and if you play again, it should display the sum of the the old and the new score. If you want to display in the start scene only the last achieved score, use “=” sign instead of “+” sign for operation.

If you want to display the highest score, you can check first if the value of GlobalScore is greater or less than the current score, if it less then assign the new value.

If GlobalScore < SceneScore : Do = Variable(SceneScore) to the value of GlobalScore

Again, I don’t have a chance to test it but in case it doesn’t work for you or you don’t understand something just ask if I’m not here hopefully someone else can help you and fix me if I explained anything wrong.

Thanks very much for your help