Save system. Again

Hi there! So I’ve been making my little game and it’s now time to implement save feature to it. So I read a bunch of tutorials, looked at the sample projects etc.
But I just can’t make it work. All of my variables in the game are global. I spent some time to make a scene variables but it didn’t work either.
I successfully can write a value of a global variable to the file (I can see the stored value in the developer console). But I can’t read a value and assign it to the global variable. Below is simplified example of what I’m trying to do.

The action description is clear about that:

Does this mean that I can store global var in storage and make something like:
Modify GlobalVariable = Variable
and read it from the storage this way?

Read and store in a scene var, and then copy that var to a global var, yes.

1 Like

Okay. So I’m writing global var into the storage (it works, value is there).
Next, I’m reading a value from the storage and assigning it to the scene var.
Next, I’m setting a value of a global var to a scene var.
So, it should work. (counter of kills should work, for example). But it isn’t!
What am I doing wrong?

I had a similar difficulty a few days ago, look how I solved it, it’s very simple :slight_smile:

Not my case =(
I already have all the variables and they’re changing during the game. I got the idea of what you did here, but it will not help me in this case.

When you read a value from storage it must be a Scene variable and the variable must be declared in the scene variable editor first, otherwise it is not going to work.

To go to the variable editor:
Right click in the scene → Scene properties → Edit scene variables

There add a variable, name it, and set an initial value either 0 if it a number value or just leave it blank if it a string.

After it should work. I believe this is the only case when you must declare the variable in the variable editor first.

I have all the variables as scene var. Yesterday in discord we had a discussion about it. I tried everything. I guess I’ll implement a save feature in my next game :joy:

Do you have the scene variables added in the scene variable editor?

Yes, I surely have. I write all of them into the storage and it works ( I can see a stored values ). I have a problem reading them back into scene vars afterwards

Try to reproduce the problem in a small project, maybe just write a value in to storege at the beginning than read the value from storage in to a scene var then pass the value from scene var to a global var then share the project if it doesn’t work for you so people here can have a look what is wrong with it. :+1:

sorry, you’re having trouble reading the global variable you wrote, right?
In my case to read it, first I read it and then I set the scene variable according to what it reads. This variable changes the global variable …
If I don’t understand your problem, sorry :slight_smile:

I think you should change the way you are approaching this.
Don’t try to save each individual variable, instead move them all into a structure called “SaveData” as child variables. Then use the ToJSON to convert that structure into a single string and save that into local storage. When you load do the opposite and convert from JSON back into your global “SaveData” variable. This will save you a lot of “lines of code” but require you to consolidate your variables and update the references.