Could I save data in this way?

Discussion and help for Easy Save 3
Post Reply
GuaiWuLieRen
Posts: 11
Joined: Sun Jul 29, 2018 3:25 am

Could I save data in this way?

Post by GuaiWuLieRen »

hi, I have written the abilities of my character in separate classes, and I need to save some values of those classes, for example, the Health of the character.
so I write some codes in below, but it can't work. any help will be greatly appreciated.

protected override void WriteComponent(object obj, ES3Writer writer)
{
var instance = (Worker)obj;
writer.WritePrivateProperty("Level", instance);
writer.WriteProperty("Position", instance.transform.position, ES3Type_Vector3.Instance);

// how can I save other classes' data in this method?
writer.Write<int>("CurrentHealth", instance.GetComponent<Health>().CurrentHealth);
}
User avatar
Joel
Moodkie Staff
Posts: 4852
Joined: Wed Nov 07, 2012 10:32 pm

Re: Could I save data in this way?

Post by Joel »

Hi there,

ES3Types are only intended to write classes and their variables. Instead you should use multiple ES3.Save or ES3File.Save calls to save the classes separately.

However, if you did wish to try to use ES3Types in this way, I see no reason for the code you're posting to not work. Please could you let me know the error you are getting?

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
GuaiWuLieRen
Posts: 11
Joined: Sun Jul 29, 2018 3:25 am

Re: Could I save data in this way?

Post by GuaiWuLieRen »

I changed the code in this way, it works right now. thanks.

writer.WritePrivateField("CurrentHealth", instance.GetComponent<Health>());
Post Reply