How to read global variables (for saving/loading)

Im adding a saving/loading system to my game, and I noticed you can only read scene variables. I know its possible to read global variables, but I haven’t found a good tutorial to do so. Can anyone help? thanks

For saving, you can just convert the Global Variable to JSON using the GlobalVarToJSON() expression (use the expression builder to find it).

When you load your saved variable, make sure you load it as JSON. Then also update the global variable by using the ToJSON() expression pointing at the scene variable (scene variable to json). This will convert it back to your global variable.

You cannot go directly from loaded data to global variable, so you will have to do this intermediary step.

Like this?

@Silver-Streak is that how you do it /\

It’s missing a step. You will need to convert the global variable to JSON before saving it.

Use the expression builder to find the Global Variable to JSON expression, and use that instead of GlobalVariable() in the first action.

1 Like