Add information saved to a loaded from XML

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
Locked
PabloAM
Posts: 26
Joined: Tue Nov 18, 2014 8:43 pm

Add information saved to a loaded from XML

Post by PabloAM »

Hello, I would like to load new information from XML and append it with data from the saved information.
I do this:

Code: Select all

            gameInfo = GameInfo.LoadFromText(gameinfoData.text);
            gameInfo = ES2.Load<GameInfo>("GameInfo");
But when I do gameIndo = ES2.Load<GameInfo>("GameInfo"); this overwrite everything even new information ( I had a new "GameMode" in the list and is removed)


Thanks!
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Add information saved to a loaded from XML

Post by Joel »

Hi there,

I'm afraid I'm not sure I understand your problem. Would you be able to explain in a bit more detail?

Also note that the code you are using will create a brand new GameInfo object, load the data into it, and assign it gameInfo variable, overwriting the one you just loading into that variable in your first line of code. If you want to load data into an existing object rather than creating a new instance, you should use the self-assigning Load methods. i.e.
gameInfo = GameInfo.LoadFromText(gameinfoData.text);
ES2.Load<GameInfo>("GameInfo", gameInfo);
All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
PabloAM
Posts: 26
Joined: Tue Nov 18, 2014 8:43 pm

Re: Add information saved to a loaded from XML

Post by PabloAM »

Hello again.

Looks like doesn´t work either :/

The think is I would like to add a new "Geometry pack" in XML and add it to gameinfo class.

So I do this:
4 packs reading from XML
4 packs reading from XML
4packs.png (33.31 KiB) Viewed 5209 times
and the gameinfo is filled with the new geopacks.

But when I try to add my saved information, it replaces everything.
3 packs again :(
3 packs again :(
3packs.png (37.95 KiB) Viewed 5209 times
What I should do?

Save User info in other alone class outside of gameinfo class??

Thanks!
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Add information saved to a loaded from XML

Post by Joel »

Hi there,

I'm still not certain I understand what you mean. Do you mean that you have a List in your GameInfo class and you want to add items to that list, rather than overwrite the entire list?

If so, you will need to remove the list from the ES2Type for your GameInfo class, save the List separately and manually add the items to your list yourself. Something along the lines of:
ES2.Load<GameInfo>("GameInfo", gameInfo);
var list = ES2.LoadList<ByPackInfo>("GameInfoList");
foreach(var item in list)
    gameInfo.geosBuys.Add(item);
All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Locked