Help with saving a structure variable to a Json file?

How do I…

I’m saving the level completions in my game in a structure variable. Currently, every level is inside of the structure variable.

The event that loads the Json file when the game is opened:

At the beginning of the scene →

Load “chapter1completions” from storage “SaveData” and store as text in tempJsonString

Convert JSON string “tempJsonString” and store it into variable chapter1LevelCompletions

And this is the event that saves the structure variable to a Json file when a level is completed:

Player is in collision with Flag (trigger once) →

Change the variable chapter1LevelCompletions[(levelChosen)]: set to 1

Save text GlobalVarToJSON(chapter1LevelCompletions) in “chapter1completions” of storage “SaveData”

What is the expected result

What should happen is the level is completed in the game, and when the game is closed and reopened, the level shows itself as completed.

What is the actual result

When I complete a level and return to the menu, the level shows as completed. However, when I close and reopen the game, it does not show as completed.

Thanks to anyone that can help me! (I apologize for not adding more images, I am currently only allowed to upload one)

There is a ToJSON(chapter1completions) function, but GlobalVarToJSON(chapter1LevelCompletions) is deprecated and probably doesn’t work.

Hi CobaltBoot, one thing you can try is to put in a condition to check that the storage group exists. There’s a lot of things going on at the beginning of a scene and it might be trying to load your data before the storage has been read.

It doesn’t have to be a sub event like my pic but you might end up having more load checks to keep separate from each other.

do you absolutely need json string?

feels like you can store level completion as a number in the storage, and then load it as number. maybe i’m wrong though

I think you’d be better off storing it as structure.array and having the levels completed as an array of booleans or numbers

And then you can use a variable to check whether user has completed a certain level.

I usually do something like user.completedlevels[currentlevel] is true show ‘level complete’ etc

Can you screenshot your events related to loading and saving storage.