[SOLVED] How to save game progress stored in a global variable?

Hello everyone!
I am creating a top-down game, and as the title suggests, I would like to understand how to save a global variable (which in this case is used to temporarily save the exceeded levels) in the mass memory of the device.
As I have read, only scene variables can be saved with JSON files … but I am sure it is also possible to save global variables, but how?
Thank you so much to anyone who has the patience and desire to help me! :slight_smile:

There is some storage action that may help you to save global variable.

1 Like

What would they be? :slight_smile:

Go Here
And download GDevelop5_save-load.zip…It will help you.

1 Like

I have already seen that example, but it is not for me. This is because I have to read the global variable, not the scene variable …
In a nutshell, I wrote:
If the global variable is 1, then write 1 in “savament” of storage “save”
If the global variable is 2, then write 2 in “savament” of storage “save”

Now, when I open the game, when I am in the menu, I would like it to read what I wrote when I press “start” and set the global variable to that data
I don’t know if I gave the idea :slight_smile:

Else you can use a scene variable as intermediate. You set the scene variable temp to the value of the global variable and pass it to storage before removing it, and load to temp from storage and set the global variable to the value of temp before deleting temp.

1 Like

You mean this way?
This makes the save

this loads the save

Then try this method. When you want to save a global var send it to a scene var and save it.then when at the beginning of the scene get that scene var and send it to global var and use it.

1 Like

Yes I did as in the picture, and I placed what tonight “loads the save” in the main menu, what it shows as soon as the game opens … but it doesn’t work, am I doing something wrong? Is it correct to use JSON files?
Thank you very much for helping!

I found a really simple and banal way, which also works on Android

Please share it for other people who might have this problem and find this topic :wink:

1 Like

it is much simpler than it seems, an external event must first be created. In this event a global variable must be created, which when it is 1, as an action changes the scene to level 1, and writes the value 1.
This procedure must be done for each level by changing only the number 1, with 2 in the case of level 2, with 3 in the case of level 3 and so on …
Now, in the main menu, set “at the beginning of the scene” and put a sub-condition that verifies the existence of a group. This as an action has the reading of the group.
as under conditions of this, we have to create a scene variable, which if equal to 1, change the global variable level = 1.
This must be repeated for all levels, obviously changing the 1 with the 2 for the second level, with 3 for the third level and so on …
That’s it, much easier to do than to explain :slight_smile: