Page 1 of 1

Trouble with Reader and Writer

Posted: Mon Jun 20, 2022 6:23 pm
by Calandryll
I'm trying to get a simple save and load working and I'm running into some errors. Here is my code:

public void LoadPlayer ()
{
if (ES3.FileExists ("TestSave", ES3Settings.defaultSettings))
{
using (ES3Reader reader = ES3Reader.Create("TestSave", ES3Settings.defaultSettings))
{
string testLoadString = reader.Read<string>("teststring");
Debug.Log(testLoadString);
}
}
else
{
Debug.LogError("no save file");
}
}

public void SavePlayer ()
{
string testString = "ere";
using (ES3Writer writer = ES3Writer.Create("TestSave", ES3Settings.defaultSettings))
{
writer.WriteProperty<string>(testString, "teststring");
writer.Save();
}
}

Initially the save works as it creates the file and I can open it to see that the property is there along with the value. When I try to load that save however, I get the error that the key "teststring" doesn't exist.

"KeyNotFoundException: Key "teststring" was not found in file ... "

Also, when attempting to save again after the save file is initially created, I get this error.

FormatException: Expected '{' or "null", found '"'.
ES3Internal.ES3JSONReader.ReadNullOrCharIgnoreWhitespace (System.Char expectedChar) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3JSONReader.cs:359)

Any help would be most appreciated. Thanks!

Re: Trouble with Reader and Writer

Posted: Tue Jun 21, 2022 2:46 am
by Calandryll
Disregard, I figured it out. :)

Re: Trouble with Reader and Writer

Posted: Tue Jun 21, 2022 9:18 am
by Joel
Hi there,

Just to clarify, ES3Reader/Writer is only used internally and from within ES3Types, so should not be otherwise used. Instead you should use caching as described here to get the same benefits in a significantly simpler way:

https://docs.moodkie.com/easy-save-3/es ... rformance/

All the best,
Joel