Saving on Android

Alright so I think I have it triggering the saves and loads now. But it isn’t working quite right. It seems to be making every variable blank, or zero, or false, depending on the type. If I make it a structure it wants me to select the specific one not the whole catagory. Do I make it an array? The JSON calls for a string though?

I’ll look through your events.

To save:
You start with a variable and convert it to a string in the json format. You then save the string to storage.

To load:
You load the string with text in the json format from storage and convert the string to a variable.

It behaves the same way if the variables you’re trying to save is a structure or an array.

Be aware once you load data from storage, it will replace the current values basically ignoring the values in the setup screen. Sometimes, you need to use the delete storage action to clear the storage. Also, you should have the condition that checks if the storage exists before trying to load from storage otherwise it will use an empty string instead of the json data.

The weird thing with GD, is that just trying to read a variable will create it. So, it can be tough to tell if the variable was 0 or if it didn’t exist so GD created it with the default value for the variable type.

Try deleting the storage. You can add the action at the beginning and then delete it afterwards or you can add a button that deletes it.

Can’t get any more simple than this

1 Like

So I’ve been messing around with it for a while now.
I can get everything working perfectly except when I close the app and restart it, it didn’t save. It saves between levels as I play, but it doesn’t seem to be actually accessing the storage of my android and creating the file. I have noticed it isn’t asking permission to use the device storage either, which also makes me think it’s not accessing it.

Is there a plugin or event to make it access android storage?

Its not like it access your device storage
But gdevelop runs inside a browser
So it access that browser storage
Where you cannot set save to be preformed when game is closed
Like you would try to write Bye after you close this forum page
You can’t

You can either perform saves at some time intervals
Or do them at some points/moments in your game

So I have save points throughout the game, and I am going through them, and it’s either not saving at those points, or its not properly loading on my load saves events.

This is how you save and how you load variables

In this post how i save pressing Q and load pressing E

So you would need that adjust to your needs
BUT be aware it save/load variables
So if you save position of player into variable then you need to change position to that variable after you load

So however and whatever you save variables at certain points
You need to load and then set stuff you want to that variables

thanks! I will go over all of this and try it out thoroughly :slight_smile:

1 Like

I somehow cannot get it to work even with my code looking, at least to me, identical to yours.

Not sure what to do short of inviting you as a colab member to take a look.

Show me screenshot of your events


Where did you found this?
image

Because all i can find is this
image

oh snap that’s probably my issue.
It says it only grabs the first part of it, if it’s a string. Interesting.

Changing that did not fix the issue.

Be aware i have dyslexia so i am kinda worst person to find mistakes

And i can’t find any mistakes in your events

In your place i would try to make different global variable structure with just one number variable
Which you set to some number and save load with some two different keys to check if its working

1 Like

Variable/VariableString() no longer exist for new events. You should just be calling the variable by name. If it’s a number and not currently a string, you could wrap the variable name with ToString() but that shouldn’t be needed at all.

This part is using a variable for the group name. So, it’s using its value. I think it should be “SaveData”

1 Like

I think Keith found your issue

I did dig trough my old project and found that this is how i did save/load check

So you should change TempSaveData to “SaveData” i mean in quotes

Thanks guys ill try this stuff out!

booya, it works! Thanks a ton guys!