Nested save

Discussion and help for Easy Save 3
Post Reply
KVinS
Posts: 1
Joined: Tue Jun 25, 2019 12:09 am

Nested save

Post by KVinS »

Hello! Earlier, I used asset just to save elementary types. Everything was OK.
Now I am trying to create a nested save:

-Character
--Name
--Health
--List <ItemController>
---ItemManager
----Id
----CurItem
----Items
---ItemManager
----Id
----CurItem
----Items

I load and save the Character with the help of LoadInto and Save accordingly.

For it, an EC3Type i'm automatically created with all the specified fields. There are no problems with the name and health.
I also created the EU3Type for ItemController with id and name.

But only it's _ES3Ref is saved!

Code: Select all

"ItemManagers":[{"_ES3Ref":724151928669719713},{"_ES3Ref":1934583549284300375},{"_ES3Ref":1923890871494309969},{"_ES3Ref":4583309440906128168}]
I tried to manually change ReadComponent / WriteComponent (in Character)

Code: Select all

			foreach (var itemManager in instance.ItemManagers)
			{
				writer.Write<ItemManager>(itemManager.id, itemManager);
			}

Code: Select all

				foreach (var itemManager in instance.ItemManagers)
				{
					if (itemManager.id == propertyName)
					{
						reader.ReadInto<ItemManager>(itemManager);
					}
				}
Then the save works.

Code: Select all

"Hair":{"__type":"ItemManager,Assembly-CSharp","value":{"_ES3Ref":724151928669719713,"_ES3Ref":724151928669719713,"goID":7320055566608279791,"id":"Hair","currentItem":null,"boughtItems":[],"currentColor":{"r":1,"g":1,"b":1,"a":1}}}
But nothing is being loaded...

Code: Select all

				foreach (var itemManager in instance.ItemManagers)
				{
					if (itemManager.id == propertyName)
					{
						reader.ReadInto(itemManager.id, itemManager);
					}
				}
I made such a code and it all worked, but now I’m not at all sure that I’m doing everything correctly =\
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Nested save

Post by Joel »

Hi there,

I moved this thread because this is regarding Easy Save 3, but was posted in the Easy Save 2 forum.

If your current solution works then that's fine. It seems like a feasible way of doing things, as long as you've always got the same number of ItemManagers when loading as you had when saving.

Another way of doing things would be to provide an ES3Settings object to force Easy Save to store fields by reference and by value, as described here: https://moodkie.com/forum/viewtopic.php ... 5698#p5698

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply