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.


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