Storage action explained

When you want to save and load anything in your game you need to use the storage events. Here I explain what each option is for when you want to read and write values in order to help you get started. After reading this I recommend to check out the Save-Load example included with GDevelop.

Storage actions will store all the data into internal storage. If you want to write or read from files, read the page about File system (only for Windows, macOS, Linux).

Write value

File: “filename”

Name of the file you want to write in to. For example, you may want to store player information in a file called “player” and game settings in a file called “settings” or you can just use a single file to save everything and call it “save” it is up to you how would you like to organize this. If the file with the name does not exists, GDevelop going to create the file.

In case of HTML5, GDevelop is not using the local file system, instead it using the web storage to store the file

Group: “Group name”

can be anything, this is basically a name that you going to assign the value to inside the file. 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 another group inside the same file like so:

Group: “PlayerPositionX” to store the X position of the player

Group: “PlayerLife” 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. The X Position of the player or the life or anything else.

Expression: the value you want to write into the file

can be anything, a number such as 12345 or text such as “this is text” or even a variable.

To get the value stored in a variable we need to use variable expressions in the field:

Object variable:

object_name.Variable(variable_name)

object_name.VariableString(variable_name)

Scene variable:

Variable(variable_name)

VariableString(variable_name)

Global variable:

GlobalVariable(variable_name)

GlobalVariableString(variable_name)

An important 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 into the file and you need to keep this in mind when you using the expressions too. The ones with a String in the expressions are for calling text variables and the ones without it are for calling number variables.

Read value

To Read a value from a file, basically the same thing:

File: Enter name of the file you want to read from

Group: enter the name of the group that has the value in the file

Scene Variable: enter the variable name you wish to use to load the value in to. It is important to be a scene variable and this field expecting the actual name of the variable and not an expression. The variable also needs to be added to the variable list in the scene properties and select the variable from the list. 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 reading from the file.

And again, Read Value is to read number only and Read Text is to read text only. You also need to keep this in mind when you select the scene variable to read the value in to. The variable need to be number to store number and text to store text.

Examples

See it in action! 🎮
Open these examples online.