Saving on Android

Using the search tool, it looks like I can’t save on android currently in GDevelop? Is there a way to do it? Here’s what I have tried. It doesn’t keep the variables changed when I reboot the app

It’s converting the literal string “TempSaveData” instead of the text inside the variable. Try removing the quotes in the 2nd line and use the variable name TempSaveData.

image

Here’s what happens when I try that


I am assuming I need to change my structure some, I’m just not sure how/where to do it.

I followed the advanced saving tutorial on the official youtube channel.

Is the string variable declared?

maybe? I am not familiar with that term.


oh I think I might see what you mean. I need to create TempSaveData as a global variable?

1 Like

okay that cleared the error, I’ll go ahead and package and test it now. Thanks so much!!

1 Like

You’re welcome. Variables are tricky. Until recently, you had to use Variable(variableName) and VariableString(VariableName). As long as the variable is declared or setup (whatever the official term is) you can use just the variable name. It will be listed in the dropdown list that appears when you start typing.

1 Like

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