Save load problems

Hi, I’m trying to use a save load system for a project that has one scene. I need to save things for objects already in the scene as well as newly created objects. This post [Solved] Save/load created objects from a few years ago seemed perfect for my needs but I don’t understand it. I’ve read many other posts and watched many videos but I can’t get it.

I think I’ve got the saving part right but I don’t understand what I’m doing with the loading part. Also, the wording of things has changed since that post, so what may have been obvious then is now confusing (my excuse).

Here are the suggested events from @MrMen [Solved] Save/load created objects - #4 by MrMen from the other post and my interpretation of them.

Save
1-3.
Save the various properties of a group object into a structure variable called Character that has named children.
4. Save the structure variable into an array variable called SaveCharacters. How did it get the [“CharacterArray”] part in it? I thought arrays couldn’t have named children? Is the array ‘blank’, that is it has no children?
5. Save the array variable to a json in the appropriate category of storage

Load, this is where I get really confused
6. Get the json from storage and save it as characters_json - what type of variable is it saved to? Just a text variable?
7. Change the text from the characters-json variable into something readable and save it into a variable called LoadStructure - what type of variable? Structure because it has the word structure in the name? But in the Save sequence it was Structure->Array->Json->Storage which would mean it would be an array?
8.Once again, how did [“CharacterArray”] get there? For every object that had its properties recorded in the LoadStructure variable, now duplicate all those things into another variable called LoadDetails? What type of variable is it? A structure? If so, I assume it has the named children from steps 1-3. But if LoadStructure is a structure then why would we now need another structure?

I’ve tried variations of different variable types where I wasn’t sure and nothing works.

Here are my events. I’m not very confident with debugging profiling stuff but I get this error when the load events are toggled on.
Unable to parse JSON: ItemJsonSyntaxError: Unexpected token I in JSON at position 0

The GDJS_Save thing has the save stuff repeated over and over (I deleted the storage to get a fresh start, so it’s not that.

I’ve also tried it with no conditions like in the example and it didn’t change anything.

Also, I will need to save different sets of info for different objects and for multiple instances of those objects. Does that mean that if I ever get something working that I have to have these steps for each set of objects that has its own set of properties? For example, for many objects, I need name, color and position. For others I need those things plus animation name or width. Could all this info be saved into one structure variable and then at the end I just have different create events? That doesn’t sound like it would work.

They’re both a structure of arrays - the structures are named SaveCharacter and LoadStructure. The child “CharacterArray” is an array. That child will be created if it’s not already present in the structures


Yes.


It’s a child of the structure that was saved. If you look at it in local storage, then you’ll find the name “CharacterArray” saved in the data. When it’s loaded and parsed into the LoadStructure variable, the children’s names are restored.


ItemJson is a variable, and should not be in quotes in the convert string action. GDevelop is trying to convert the string “ItemJson” and not the contents of the variable, hence the error.

1 Like

Thank you MrMen. I deleted the quotes and rejigged the variables. Things are starting to work but very buggy and the camera is going crazy. But I will see if I can solve those things. But I wanted to check, have I now got the variables right?

I couldn’t find that (“ItemArray”) but I didn’t make the child, just hoped things would sort themselves out.

Because I didn’t type it into the actions :face_with_open_eyes_and_hand_over_mouth:. I have now and I think everything is right, as it works. But I’m getting inconsistent results which I think is because I haven’t yet worked out what the right conditions are for the saving. Depending on what I try, either multiples of an object are created or only the most recent objects are created. But I’ll try to sort that out.

1 Like