Modifying Type

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
Locked
BFRETHGIL
Posts: 23
Joined: Wed Jun 13, 2018 8:25 pm

Modifying Type

Post by BFRETHGIL »

What's the best way to modify a new type, let's say I added a Person class with "name", and "email", and saved it as a new type, and later I want to add a new parameter "age" and update the type?
Your asset says
This type has already been added. Modifying or updating it will make previously saved data of this type incompatible with the new version.
The solution is to remove the file, but when I release the app to the store, I don't want to remove the user's file because they have all their information there- (points/levels),
Do you have any copy method or something like that?

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

Re: Modifying Type

Post by Joel »

Hi there,

The best way to do this is to create two ES2Types: one for your old data, and one for your new data.

Then to control which one Easy Save uses, you can use ES2TypeManager.AddES2Type.

So let's say we have two ES2Types: ES2Type_MyTypeOld and ES2Type_MyTypeNew. You would first want to set the ES2Type_MyTypeOld, which you can do by calling:
ES2TypeManager.AddES2Type(new ES2Type_MyTypeOld());
Now you can load your old data using ES2.Load so that it can be re-saved using the new ES2Type. Once loaded, you need to tell Easy Save to use the new ES2Type, which you can do using:
ES2TypeManager.AddES2Type(new ES2Type_MyTypeNew());
Now we can save the data we just loaded back to the file, and it will use the new ES2Type.

You might also want to save a piece of data telling you that the data has been updated. For example, you could save a tag containing a version number, which you update whenever you modify the format.

For anyone reading this who is using Easy Save 3, you do not need to do this. Easy Save automatically handles updates to ES3Types.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
BFRETHGIL
Posts: 23
Joined: Wed Jun 13, 2018 8:25 pm

Re: Modifying Type

Post by BFRETHGIL »

It sounds a bit complicated to deal with versions, do you recommend to upgrade to Easy Save 3?
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Modifying Type

Post by Joel »

If possible I would upgrade to ES3, though I also recommend making a backup of your project beforehand.

To upgrade files from ES2 to ES3 you will need to load the data using ES2, and then re-save it in ES3.

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