how do I save a global variable in a text file?

How do I save the value of a global variable in a file and then reread it? If someone can help me, I’ll thank them

There are lots of topic about it (storage), but in summary it is just:

Conditions: Save button pressed Actions: Write GlobalVariable(variable_name) in group "group_name" of file "file_name"
And then:

Conditions: Load button pressed Actions: Read group "group_name" from file "file_name" and store the result in temp_variable_name Do = Variable(temp_variable_name) to the value of global variable variable_name

Hope it helps, you can also search for other topics about it :slight_smile:

what you explain to me I understand but I have doubts about where I get the group name because at the time of programming I do not know, I also need to know how I do in order to know what type of file should keep the value of the global variable, I know that be in the same where the .gdg file is saved, if you could help me with that topic I would appreciate it, because I have used this program recently and there are things that are not exfoliated in the tutorials

You decide what the group name is going to be. Can be anything. The group is basically a “label” for the value. The value get saved with that group name so the next time you want to load the value you can use the group name to get whatever value is stored under the group. For example if you want to store the X and Y position of the player you can say, save X position in “groupX” and save Y position in “groupY” so next time you want to get the last saved X position of the player you can use the name “groupX” to get the value…

In case of native platform GDevelop generate a simple text file with XML syntax inside. You don’t need to have the file, GDevelop going to create it. In case of HTML5 the same action is going to use the web storage.

This is an explanation I did some time ago:

And here is an example:

One more thing, you may be able to write/save the value of a global variable directly, but when you read/load the value it need to be stored in to a scene variable then you can pass the value to a global variable if you need to.