im having issues making my game save highscore and currency when i close the app and open it again, it saves and updates everytime i play the game but as soon as i quit game everything is set to 0 again.
p.s sorry im very new to using gdevelop!
For reasons I don’t understand, you cannot use storage directly into a Global Variable.
Storage can only be loaded into a Scene Variable, so your 2 “GlobalVariable()” calls will not work.
What you’ll need to do is store them in a Scene Variable, then have a SEPARATE event that then takes that scene variable data and stores it in a Global Variable.
ok apologies in advance i understand this but am having trouble figure out how to execute this now
so the first screenshot was events from my main menu, i’m now struggling to figure out how to take the information that would be saved in the scene and display it on the main menu.
also would the code from the first screenshot just be moved to the scene where the score is counted?
again sorry im very new and trying my best to learn
No worries at all. Took me a bit to grasp how to use the storage actions as well.
I would actually say your events should be fine, as long as your “currency” variables are getting updated appropriately elsewhere.
Whenever you’re going to do “loading”, whether that be at the start of the game or after pressing a “Load” button, you just need to have your 2 storage events you have now, but have them store the info in a Scene Variable.
Then add 2 events that basically do “Set Global Variable “Currency” = SceneVariableNamehere”, as well as “Set Global Variable “highscore” = SceneVariableNamehere”. This will allow you to load your data into the scene variables, then load the scene variables into the Global Variables.
thankyou for this, i would never have figured out that global variables cant be saved in storage, so i managed to do what you suggested (i think), i now have everything being saved to scene variables and updated the storage parts to read scene variables, but it still wont save when the game is exited and started again.
I’m just glancing at your image here, but the order of events make it seem that the game overwrites the save data before loading it, so essentially “not loading the data”.
Try moving it to be the first event in the event sheet so it checks and loads the save data before saving in it.
yep, definitely.
about number of exports, you can test this without exporting actually (just by playing in Preview mode) - there is an event to delete storage actually, or is it called “clear storage”?
you can put this in a “key released” condition event, and it should delete the storage(s) and quit the game immediately so the game won’t save the currency and highscore into storage. (a “change into scene” with same scene name might also work)
this still isnt saving the highscore or currency values when the game is closed and reopened, also tried exporting and still no luck, i’m so lost at this point
assuming you did create the “delete storage”(s) and-quit-game event to prevent it saving by accident (not the problem at the moment since you don’t seem to able to load it as-is)…
maybe you don’t need “Load storage storagename in memory”?
Here’s my loading highscore event for an arcade game.
(first it loads and stores it into a scene variable, then the global variable takes the value of that scene variable, then finally I update the highscore text)
It’s worth noting I only save the highscore when the player collects and object and their score is now higher than the highscore. Hopefully it’ll help you?
so in your 2nd picture, in beginning the game loads from storage, and pass the value to the Scene variable, and the event below it with no condition, it’s changed to Global variable, which I think is 0. reverse that event to “Change the global variable highscore: set to Variable(highscore)”.
unless i’m missing something, hopefully not!
There is a storage save-load example. Compare your events with it when in trouble.
‘store value in highscore’ / no need for Variable().
and like cat said, you got your variable actions reversed.
and the text actions should come after, not before.
the second image is my main menu events so the highscore and currency are only in global variants at this point, the way i first tried to write and read storage was using global variables but it didnt work, even though i think i had it set up properly, the way it is right now the score and currency are gathered in the play scene and transferred to global variables. i’ve tried so many alternative ways to do this and none have worked yet, now i feel like i understand it less sorry but im so confused at this point, would anyone be able to kindly show me an example of what i need in an image? my next plan is probably to try and integrate the main menu and gameplay scene into one and maybe that would be easier…
this is unexpected because I found out that what I needed to do was “don’t load the storage” at the beginning of the scene. IDK why but it just works @@