Saving Global Variables?

So is there a way of saving and reading them directly? Cause I have like 50 global variables and it would be kinda time waste to create scene variables for each one to then read them from there… honestly global variables aren’t any use if that’s the case? Of course I’ll do it if I have no choice, but I checked around and saw bouh say something about converting them or something here: Global variable and storage! - #6 by Phenomena

thanks.

Actually is very simple to simply load/store them in a scene var when needed, I’ll just do that.

Why you need to do that? You can acces directly to Global variable.

You can also put every global variable inside a Structure, and then save the structure variable into storage. You’ll then have to convert the JSON into a temporary variable, and then copy the structure’s values back into the original global variable when loading the game again.
See Variables [GDevelop wiki]
There’s no example of saving structures yet so if you need help, I can screenshot my (convoluted) system that I did for my inventory.
I’m not sure how else to save many variables like that.

@Tarsio , it’s a problem with Storage action (the events to save the game). Currently it only accepts Scene variable for completely unknown reasons.

1 Like

Yeah, thought it was simple but it doesnt wanna work. Basically I save the globals, then I load and and read them to a temporary scene variable, then make the real global variables equal to those scene variables, but it doesn’t wanna work yet, tryna find what I’m doing wrong

Good luck - personally Storage is quite confusing!
If it helps I’ll put my events here for the inventory:

To save


Essentially it’s a loop to save every inventory item’s quantity into a temporary scene variable called TempSave, you can think Temp.SlotNum as the “i” increment variable.
After that the temporary save variable gets converted into a JSON (I think it shouldn’t be repeated).

To load


Bit similiar, load from storage, parse structure from storage… I’d like to think it explains itself. Hopefully!

Refer to the example when stuck :slight_smile:
https://editor.gdevelop-app.com/?project=example://save-load