Save & Load game

So in native game if I want save global variables (Example: Gold, Levelups, LevelUpPoints, Xp) and load them, what should I do in events?
Save:
Storage → Write a value → File: “What to write?” → Group: “What to write?” → Expression: “GlobalVariable(Gold)”?
Load:
Storage-> Read a value → File: “What to write?” → Group: “What to write?” → Scene variables: ? (I want load global variable so should I write here “GlobalVariable(Gold)” even it says scene variables?

If someone can help what should I write in “File” and “Group” and “Expression” and how that save/load thing works. I see that it creates Gold, levelUps, Xp files in the folder where game is compiled when it saves the game, but I can’t load them when I shut down the game and open it again.

Yeah, I have read lot of topics about this, but I really appreciate if someone could help.

Ps. Is there coming in future GDevelop versions save and load actions which makes this thing lot of easier, so should I forget this question and wait for that?

File: “filename.txt”
-can be anything, name of the file you want to write in to, if the file does not exists, GDevelop going to create the file

Group: “Group name”
-can be anything, this is basically a name that you going to assign the value to. By using groups, you can store multiple values in the same file. For example the position of the player can be stored within a group and life of the player can be stored within an other group in the same file like so:

Group: “Player_position_X” to store the X position of player
Group: “Player_life” to store the life of the player

When you load the value from the file, you can use the group name to specify what value you want to read from the file.
X Position of the player or the life or anything else.

Expression: the value you want to save
-can be anything, a number such as 123331 or text such as “asdadada” or even a variable.

Object variable:
object_name.Variable(variable_name)

Scene variable:
Variable(variable_name)

Global_variable:
GlobalVariable(variable_name)

The main thing you need to keep in mind, Write Value can be used only to write number and Write Text can be used only to write text in to the file.

To Read value from file, basically the same thing:

File: Enter file name you want to read from
Group: enter group name that has the value you want to read
Scene Variable: enter variable you want to use to load the value in to, I think it needs to be a scene variable, and the variable also need to be added inside the variable editor, in case you want to store the value inside a global or object variable, just use the scene variable to pass the value over to a global or object variable after read but you can try to read the value straight in to a global variable or object variable, I don’t know for sure if it works with other than scene variable. Give it a try.

And again, keep in mind Read Value is to read numbers only and Read Text is to read text only.

I suggest to take a look at the “Level editor.gdg” example comes with GDevelop, it gives you a basic example how to make a save-load system using storage actions.
You can also checkout my example here:
gametemplates.itch.io/template-save-load

4ian did mentioned long ago, he may going to add save-load actions to make it easier, but finally it never been added to the road map but not much happening on the road map these days anyway.
I hope I’m wrong, but personally I don’t expect new features to come to GDevelop in the near future, devs seems too busy :frowning:

In case anything is coming, according to GitHub seems like 4ian is playing with the idea of replacing the native engine (SFML) with something better but no announcements or anything, he has just mentioned in a topic he was looking at Cocos2D-X to be used with GDevelop “but looks more difficult to integrate”, so it may be nothing maybe his next plan, who knows.
His not sharing any of his future plans, ideas, thoughts and progress with the community these days :frowning:

2 Likes

Hey! Thank you a lot such a long explanation, ddabrahim!
Now I understand. I did save/load thing so, it read saved Global variables example from SceneVariable(Save.Gold) if globalVariable (Continue) = 1 and in scene1 it always and trigger once: GlobalVariable (Gold) = GlobalVariable (Gold) + SceneVariable(Save.Gold). It works and thank you again, you rock!

Hmm, it would be pretty cool if that kind of system is coming, but yeah… GDevelop team needs funding to develop this more.
But this program is already pretty good and free, so I don’t complain! :smiley: I hope GDevelop team still keep working this even they have their own lives and studys and works! Because this have potential.

1 Like