Save and Load a variable enum type

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

Save and Load a variable enum type

Post by PabloAM »

Hello, I´m having a trouble trying to read a enum saved.

User Type:

Code: Select all

public class ES2UserType_GameModeButtonInfo : ES2Type
{
	public override void Write(object obj, ES2Writer writer)
	{
		GameModeButtonInfo data = (GameModeButtonInfo)obj;
		// Add your writer.Write calls here.
		writer.Write(data.icon);
		writer.Write(data.name);

	}
	
	public override object Read(ES2Reader reader)
	{
		GameModeButtonInfo data = new GameModeButtonInfo();
		Read(reader, data);
		return data;
	}

	public override void Read(ES2Reader reader, object c)
	{
		GameModeButtonInfo data = (GameModeButtonInfo)c;
		// Add your reader.Read calls here to read the data into the object.
		data.icon = reader.Read<System.String>();
		data.name = reader.Read<Globals.GameModeEnum>();

	}
	
	/* ! Don't modify anything below this line ! */
	public ES2UserType_GameModeButtonInfo():base(typeof(GameModeButtonInfo)){}
}
Looks like data.name = reader.Read<Globals.GameModeEnum>(); is not been readed (or saved)

Any suggestion?

Thanks!

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

Re: Save and Load a variable enum type

Post by Joel »

Hi there,

Using System.Enum as the generic parameter should fix your issue.

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

PabloAM
Posts: 26
Joined: Tue Nov 18, 2014 8:43 pm

Re: Save and Load a variable enum type

Post by PabloAM »

Thanks you very much by your faster reply :)

I have tried this but doesn´t works:

Code: Select all

data.name = (Globals.GameModeEnum)reader.Read<System.Enum>();

Code: Select all

InvalidCastException: Cannot cast from source type to destination type.
ES2Reader.Read[Enum] (.ES2Type es2type)
ES2Reader.Read[Enum] ()
ES2UserType_GameModeButtonInfo.Read (.ES2Reader reader, System.Object c) (at Assets/Easy Save 2/Types/ES2UserType_GameModeButtonInfo.cs:29)
ES2UserType_GameModeButtonInfo.Read (.ES2Reader reader) (at Assets/Easy Save 2/Types/ES2UserType_GameModeButtonInfo.cs:20)
ES2Reader.Read[GameModeButtonInfo] (.ES2Type es2type)
ES2Reader.ReadList[GameModeButtonInfo] (.ES2Type type)
ES2Reader.ReadList[GameModeButtonInfo] ()
ES2UserType_GameInfo.Read (.ES2Reader reader, System.Object c) (at Assets/Easy Save 2/Types/ES2UserType_GameInfo.cs:35)
ES2UserType_GameInfo.Read (.ES2Reader reader) (at Assets/Easy Save 2/Types/ES2UserType_GameInfo.cs:24)
ES2Reader.Read[GameInfo] (.ES2Type es2type)
ES2Reader.Read[GameInfo] (System.String tag)
ES2.Load[GameInfo] (System.String identifier)
MainGame.Awake () (at Assets/MainGame.cs:74)
Any other suggestion?

Best regards

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

Re: Save and Load a variable enum type

Post by Joel »

Hi there,

It looks like your type list might need refreshing. You can do this by going to Assets > Easy Save 2 > Manage Types and press Refresh ES2Init.

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

Locked