Page 1 of 1

File path confusion (noob)

Posted: Fri Jun 21, 2019 4:56 am
by owaaan
Hello,

I've been looking at the documentation, and the filepath has got me a bit stumped.

I had it working in EasySave 2, but I'm getting this error in EasySave 3 with very similar code:

FileNotFoundException: File "C:/Users/Owen Alexander Bowes/AppData/LocalLow/DefaultCompany/Polymath/SaveData.es3" could not be found.
ES3.Load[T] (System.String key, ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:268)
ES3.Load[T] (System.String key) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:240)
LoadManager.Load () (at Assets/Scripts/SavingLoading/LoadManager.cs:17)
LoadManager.Start () (at Assets/Scripts/SavingLoading/LoadManager.cs:12)

Here's the code I'm using to load:
baseManager.arrowAmount = ES3.Load<int>("arrowAmount");
baseManager.bowAmount = ES3.Load<int>("bowAmount");
baseManager.swordAmount = ES3.Load<int>("swordAmount");
baseManager.isRaining = ES3.Load<bool>("isRaining");

And the code to save:
ES3.Save<int>("arrowAmount", baseManager.arrowAmount);
ES3.Save<int>("bowAmount", baseManager.bowAmount);
ES3.Save<int>("swordAmount", baseManager.swordAmount);
ES3.Save<bool>("isRaining", baseManager.isRaining);

I know I am missing the filepath parameter, but I'm not sure how to set that up.

Re: File path confusion (noob)

Posted: Fri Jun 21, 2019 6:15 am
by Joel
Hi there,

This error happens when you try to load data from a file but that file does not yet exist (because no data has been saved yet). In this case you should either use ES3.FileExists to check whether the file exists, or provide the default value parameter for the ES3.Load method.

All the best,
Joel

Re: File path confusion (noob)

Posted: Sat Jun 22, 2019 8:38 pm
by owaaan
Thanks for the reply. Sorry, I'm not sure what you mean by a default value parameter.

Can you please give me a detailed example? The documentation is not clear to this noob.

Re: File path confusion (noob)

Posted: Sat Jun 22, 2019 8:38 pm
by owaaan
Do you mean create a file? If so, how do you do that and where do you store it?

Re: File path confusion (noob)

Posted: Mon Jun 24, 2019 6:54 am
by Joel
Hi there,

The defaultValue parameter is documented in the API reference: https://docs.moodkie.com/easy-save-3/es ... /es3-load/

For example, the following code will load the data, or if there is no saved data, it will return whatever was specified for the defaultValue parameter:
// This will return 123 if there is no data to load.
int myInt = ES3.Load<int>("myKey", 123);
Just to clarify, I do not mean create a file. This is done automatically when you call the save method.

All the best,
Joel

Re: File path confusion (noob)

Posted: Wed Jun 26, 2019 6:23 am
by owaaan
Thank you. It is working now. I must have tried to load before saving anything. I understand that a file must be created automatically when saving. To prevent this happening in my game, I could check to see if a file exist and, if it doesn't, grey out the load button.

I'm sorry to be slow, but I'm not totally sure what this means:

defaultValue

[Optional] The value we want to return if the file or key does not exist.

What value are you returning?

Re: File path confusion (noob)

Posted: Wed Jun 26, 2019 6:52 am
by Joel
Hi there,

Glad that's working for you now.

What you provide as the defaultValue parameter will be returned if there is no data to load. For example, if you provide 123 as the defaultValue parameter, if there is no save data to load from, 123 will be returned by the method.

All the best,
Joel