code doesn't process after I use ES3... ? I think?

Discussion and help for Easy Save 3
ariza8627
Posts: 16
Joined: Sun Jul 07, 2019 8:06 pm

code doesn't process after I use ES3... ? I think?

Post by ariza8627 »

Sorry for being such a hindrance...
so I don't understand. Hopefully this makes sense to someone else.
I have this code:
public void saveTheGame()
{
ES3.Save<int>("playerHP", _BaseStats.playerHealth);
ES3.Save<string>("currentLevel", _BaseStats.currentLevel);
ES3.Save<string>("currentEnemyWeapon", _BaseStats.currentEnemyWeapon);
ES3.Save<string>("currentEnemy", _BaseStats.currentEnemy);
//...many more like above statements
}

and then I have:
public void continueGame()
{
saveTheGame();
_BaseStats.playerHealth = ES3.Load<int>("playerHP");
_BaseStats.currentLevel = ES3.Load<string>("currentLevel");
_BaseStats.currentEnemyWeapon = ES3.Load<string>("currentEnemyWeapon");
//...many more like above statements
SceneManager.LoadScene(_BaseStats.currentLevel);
}

but it will not switch scenes but I initialize the string variable currentLevel to the first scene. Even more,
public void saveAndExit()
{
saveTheGame();
Application.Quit();
}
^this function will not close the game when I build a version.
What am I doing wrong? I've never used a save system before so this is honestly quite confusing that it just wont work because logically to me, I believe it should.

Thanks for helping this clueless person with their project, i guess...?
~ashenAlex <-- my signature ; )
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: code doesn't process after I use ES3... ? I think?

Post by Joel »

Hi there,

Easy Save will only be able to stop the execution of a method if an error or exception occurs.

Are you getting any errors to console? Would you also be able to check your log file for errors? Also if your code is being called from a try/catch block, you will need to remove this or ensure that any exceptions are rethrown after they are caught.

You should also try putting Debug.Log calls before and after each of your method calls to ensure that they are actually getting called.

Something unrelated which I noticed is that in your continueGame() method you are calling saveTheGame() before loading. This makes the load calls redundant as it will always be loading the values which have just been saved.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
ariza8627
Posts: 16
Joined: Sun Jul 07, 2019 8:06 pm

Re: code doesn't process after I use ES3... ? I think?

Post by ariza8627 »

hey, so i got rid of the redundancy in the continueTheGame() method and I ran the game in the default like, non-built version which I never do because the game doesn't scale right. I'm sure there's a really easy fix, I've just never looked it up.

So I ran the game in Play mode and I got 1 error when I pressed the Exit Game button. The error says: "InvalidCastException: Specified cast is not valid. ES3Types.ES3Type_int.Write (System.Object obj, ES3Writer writer) (at Assets/Plugins/Easy Save 3/Scripts/Types/Primitive Types/ES3Type_int.cs:18)". When I double click on the error in the console, it brings up the ES3Type_int script in visual studio and it highlights:

public override void Write(object obj, ES3Writer writer)
{
writer.WritePrimitive((int)obj);//This line is highlighted
}

When in Play mode, if I were to click the "continue" game button to play the game I get a different error. This one reads: "FileNotFoundException: File "C:/Users/Alexander Riza/AppData/LocalLow/DefaultCompany/Text Adventure Game/SaveData.es3" could not be found. ES3.Load[T] (System.String key, ES3Settings settings) (at Assetss/Plugins/Easy Save 3/Scripts/ES3.cs:268)". Double clicking the error, it brings up the ES3.cs script in visual studio and highlights:
public static T Load<T>(string key, ES3Settings settings)
{
using(var reader = ES3Reader.Create(settings))
{
if(reader == null)
throw new System.IO.FileNotFoundException("File \""+settings.FullPath + "\" could not be found.");//This line is highlighted but I'm sure you already knew all that.
return reader.Read<T>(key);
}
}


Sorry if I misspelled something but I hope I didn't.
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: code doesn't process after I use ES3... ? I think?

Post by Joel »

Hi there,

The InvalidCastException is because you're trying to save a variable using ES3.Save<int>, but the data you're saving is not an int. If you look at the stack trace for the error message it will show you what line in particular.

With regards to the FileNotFoundException, this is because you're trying to load data but no data exists. You should either use ES3.FileExists or ES3.KeyExists to check whether data exists before loading, or specify the defaultValue parameter in the ES3.Load method.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
ariza8627
Posts: 16
Joined: Sun Jul 07, 2019 8:06 pm

Re: code doesn't process after I use ES3... ? I think?

Post by ariza8627 »

Wow, I've been messing with my code all day today and I realized after just a few minutes how dumb I seemed. The errors were just from me not double checking I had everything right and getting discouraged from it not working...
Anyways, I have it working, to an extent. Obviously I have a lot of work ahead of me, making sure the currentLevel and currentEnemy are saved, that type of information. But for that I need to put an Easy Save 3 Manager on any scene I want info saved on. I'm kind of having trouble and I'm sure I'm just doing it wrong. See, as of now, I'm just trying to copy and paste the Easy Save 3 Manager but that isn't allowed and I can't get the "Assets > Easy Save 3 > Generate New Reference ID's" to work. Actually when I do that I am forced to remove the component and reimport Easy Save 3 to fix the error because it tells me I have an object being set to null or something like that. It's the problem I was initially having but fixed by reimporting. The 999+ error messages thing. I'd pull up the error but I don't want to get stuck with it, hope that's ok. I CAN get the error for you but not if you don't need it.
Thanks for all your help Joel!
~ashenAlex
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: code doesn't process after I use ES3... ? I think?

Post by Joel »

Hi there,

The Easy Save 3 Manager should be automatically added to your scene with new reference IDs. If it's not, you can go to Assets > Easy Save 3 > Enable Easy Save for Scene.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
ariza8627
Posts: 16
Joined: Sun Jul 07, 2019 8:06 pm

Re: code doesn't process after I use ES3... ? I think?

Post by ariza8627 »

So I already made all these scenes, I just want a way to save progress on each and I don't understand how to do what you say because the option is grayed out.
What I am trying to do is, I set the scene to "Active" and I highlight the scene by clicking on it and then as you can see in the attached picture, I hit Assets, find Easy Save 3 and hover on it to open the drop down menu. Still, the Enable Easy Save for Scene option seems as if it cannot be clicked and pressing it does nothing. Am I doing this wrong?
ariza8627
Posts: 16
Joined: Sun Jul 07, 2019 8:06 pm

Re: code doesn't process after I use ES3... ? I think?

Post by ariza8627 »

lol shit, forgot to attach pic... here it is.
Attachments
Unity screen
Unity screen
grayedOut.png (73.43 KiB) Viewed 3252 times
ariza8627
Posts: 16
Joined: Sun Jul 07, 2019 8:06 pm

Re: code doesn't process after I use ES3... ? I think?

Post by ariza8627 »

Also, separate question.
Why does it take so long to save the game?
I use a save method when you die, you click this button and it saves the "new" values but it takes like 6 seconds as opposed to the instant before I implemented a saving system.
Any fix to this?
I just use ES3.Save<int>...
and ES3.Load<int>("var x")...
But it seems like it takes forever! I'd really appreciate a fix to be faster. Thanks.
~ashenAlex
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: code doesn't process after I use ES3... ? I think?

Post by Joel »

Hi there,

If the option is greyed out then it means there is already an Easy Save 3 Manager in your scene. Would you be able to take a screenshot of your active scene? Also if you delete the Easy Save 3 Manager, it should be automatically regenerated with new reference IDs.

With regards to it taking long to save the game, I've had no reports of saving an int taking a long amount of time. Please could you take a screenshot of the Profiler for the ES3.Save call so I can see what is happening?

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