My Loading of GlobalVariables are not working when apps closed?
I know they are saving and displaying, as if I go to the menu and come back to level 1, they are there, but when I exit the app and come back, everything is 0?
Thanks in advance.
Hi do some checks of the variable types make sure they are the same, I mean your MoneyAmount and DiamondAmount are a Global type string?
Is important because when you use Read there is two types of Read one is for numbers and the other is for strings.
In your case as the Globals are string types you need to use Read a text storage.
Later you’re writing in LocalStorage all the time.
Use Write GlobalVariableString(… on specific event like a player collision with coin or player collision with diamond and ensure that event only runs one time adding Trigger Once.
This is how I do the check of Storage all this groups are in a main Event Begin of the scene.
First check if doesn’t exist then assign defaults
If exists assign to a scene variable.
I thought you could not read a GV, you had to read a SceneVar, then write it to a GV. Right?
Sorry, I misread and my first response was very incorrect, so I deleted it.
Variable expression, counterintuitively, does not return the variable, but the numeric value of the variable as it is a number expression (if you want this to change, I do too and started working on a patch for that). So by doing what you are doing, you are setting your global variable to the numeric value of what was in storage. To do a real copy as of now, I don’t think (sadly) that a copy action has been exposed to the events, the only way I know to copy a variable into another one would be via JSON, something like this:
Thanks, let me try the above and the “” version.
Nope, but this might, I have no exports left and the Network preview never works for me, so I’ll try tomorrow.
If you load storage into memory, you also need to close it to save the changes :
May I ask why you are loading it into memory? And why are you writing to storage in an unconditional event?
I’d suggest writing it when you change a variable would seem a better move. And at that point write it straight into storage, rather than to memory.
So this is crazy.
All I want to do is save(write) a GlobalVariable (every frame) and on startup (and every frame), show(read) it.
I am updating every frame, as it’s a clicker game, where money drops and you can click a button, actually on writing that, I know I can just add the condition when the item is clicked, ill do that later.
Why is this not simple?
I tried this and converted my ‘Diamonds’ to Scene Variables, but they are not loading on exit/return:
GDevelop Highscore Tutorial 2021 - YouTube (I think he did not cover that)
I changed my ‘Cash’ to read & write in Values, but that’s not worked either.
I added storage and removed storage, but that’s not worked either.
I thought this would be easy.
This is me as of now:
Cash is GV set to Value Read Write
Diamonds are SV set to Value Read Write
The GV works when I exit the scene, but not when I exit the game…?
Your condition looks for storage named Save - with a capital ‘S’. You write to a storage name save - with a lower case ‘s’. I suspect, given that GDevelop is case sensitive, they’re being treated as two different things, and the read never happens because the storage Save - with a capital ‘S’ - doesn’t exits…
Thanks bud, I’ll try it now.
Done, problem was the capital S and not and using a cross between Scene and Global Variables:
Why use GlobalVariables if you cannot load them on start up?
Because they persist between scenes?
OK, so I cannot save or read a GlobVar, I have to use ScenesVar.
But ScenesVar do not not persist between scenes, so I have to load everything up, or when an action takes place, write to a ScenesVar & a GlobVar?
You use the scene variable to store as. temporal then assign your global variable the value of the scene variable.
Why not just use GV?
Why temp it?
Why not just read/write from a GV, seems easier and quicker.
It’s because the Read from storage can not be directly assigned to Global variables. If you read the helper above it says store into a scene variable