How to save Variable in a Native Game?

I am making a HighScore game so that’s why I need to know how to save variables in Native Games. I already saw some tutorials and followed it but it never worked but when I tried it on a WebGL Game the score just saved and loaded successfully!
So in Native Game the HighScore successfully saves in an XML file but it can’t be loaded again in the Game.
I think that when I save it multiple times and edit the XML file with Notepad, I can see multiple Groups with same name that’s why the Variable not loading…
Please help me to save and load variables successfully. If you can give me a example, that would be so good!
Note: If you are creating the example please use version 3 because I have 32-bit window so can’t install GDevelop 5 :stuck_out_tongue:

Wow, version 3 !?, GD 4 has support for 32 bits, and you can compile GD 5 yourself to get a 32 bit version :wink:

Check if the group you’re using start with a number, the bug was discovered here: [url]Structured file is writing new values instead of overwriting]
And reported here:
But no solution so far, and probably there won’t be, as GD 4 is being discontinued :frowning:

How to compile GD 5 for 32-Bit??? But anyways I am using version 3 because 4 just freezes when I open “Scene Editor”.
The group is named as “1”. Everyone names it like this! And it works for WebGL games and not for Native Games. Why???
I created a new project for WebGL and Copied the exact scene and pasted it on the WebGL game… Then how’s this possible… I think that it can’t load the file easily and it creates more than 1 groups with the same name,“1”. :confused: :confused: :confused:

If you follow the link to the GitHub issue you’ll see that we suspect it’s a problem from the XML parser, it does not affect web games because JSON is used instead XML.

Note that groups names are dynamic strings, if you name your groups “g1", “g2”, “g3”, etc instead “1”, “2”, “3” you can access them as easy as before, if right now you’re doing something like:


you can do:

"g" + ToString(Variable(group_index))

And as “gN” groups don’t start with a number you won’t face the bug :slight_smile:

Can you please give me an example file??? :frowning: :frowning: :frowning:
I am still facing the issue…

How are your events?

Hmm… OK I will soon give a google drive link for the example and an image of the events… :slight_smile: :slight_smile: :slight_smile:

Here is the example:
[spoiler]Go try and take experiments at it to help me… :smiley: :smiley: :smiley:[/spoiler]

Please help as soon as possible!!! :stuck_out_tongue:

Here, as I explained just change the group “1” by “g1” (for example, anything that doesn’t start with a number works).
Also, it seems that the file must contain an extension, any extension, so I’ve renamed the file “Highscore” as “Highscore.sav”, you can use “Highscore.txt” to be able to open easily with a plain text editor :slight_smile:
Problem.gdg (22.4 KB)

Sorry! The file you uploaded doens’t load. It says something like:“The file is created in too old version of gdevelop. Please use Gdevelop 2 to open it”
Can you create it for Gdevelop 3?

No man, I won’t download GD3 for this, there are 32-bit versions of GD4 :wink:

Hmm… :confused:
I think I got the problem! :slight_smile: When I preview the game in the editor, it works great and saves & loads the high score easily but when I publish it, it doesn’t save the file… I went to the project folder and found the file which is saved by the editor and moved it to the Compiled Game folder and what? Do you know…
It Loaded The File! :laughing: And the it works great. It saves the file properly.
[spoiler]It now saves & loads the file but the problem mentioned below occurs![/spoiler]
But when I press the “Save” button, the game crashes.
This is the only problem now!
Here’s the GD file by which I am having the problem:
Please help me! I need your support!

It works fine in preview and compiled game (without copying the file, GD creates it automatically), if you use a filename with an extension as I said before, for example .txt :wink:
Here is the project fixed, it was saved with GD4 so maybe you won’t be able to open it, but saved as .json too so you can open it in GD5 (also working fine, btw in GD5 the file doesn’t need an extension): (8.45 KB)

Thanks a lot! Worked for me.
I was still having the crashing problem then I got a idea! :bulb:
I removed the object instead I added “When a key presses” behavior and:
It worked! :smiley: You are true genius. :mrgreen: Thanks!