Trouble with Reader and Writer
Posted: Mon Jun 20, 2022 6:23 pm
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!
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!