Using ES3 Reader key not found exception

Discussion and help for Easy Save 3
Post Reply
Frank
Posts: 5
Joined: Wed Mar 08, 2017 7:54 pm

Using ES3 Reader key not found exception

Post by Frank »

I'm using ES3 and getting a KeyNotFoundException.

Code is like so:

using (ES3Reader reader = ES3Reader.Create(filename))
{
long dateTime = reader.Read<long>("myDateTime");
long gameTime = reader.Read<long>("myGameTime");
}

My save file looks like this:

{
"myDateTime" : {
"__type" : "long",
"value" : -8585468269062238189
},
"myGameTime" : {
"__type" : "long",
"value" : 655333938000000000
}
}

When I trace the parser, it seems like it's reading one key and value and then reads } } and closes the reader, disregarding the second property.

Maybe I'm doing it wrong? I've used ES2 for years and this approach worked fine before.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Using ES3 Reader key not found exception

Post by Joel »

Hi there,

ES3Reader/Write is now only used internally and should not be used, as it is unlikely to work how you expect.

Instead you should use caching if you want to benefit from making multiple reads/writes with a single I/O call, which is documented here:
https://docs.moodkie.com/easy-save-3/es ... rformance/

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Frank
Posts: 5
Joined: Wed Mar 08, 2017 7:54 pm

Re: Using ES3 Reader key not found exception

Post by Frank »

Ah, that explains. Thanks.

One more question: How do I write the cache to a file?

ES3.StoreCachedFile() stores it to the default file.

ES3.StoreCachedFile("myfile"); says "FileNotFoundException: The file 'myfile' could not be stored because it could not be found in the cache.

Do I have to feed it ES3settings with a path set to the file I want? Do I have to create the file first? This all seems too much hassle to be the right way to do it, but after checking the guides, examples and tutorials, I couldn't figure out how to do this. Except copying the default file to the path I actually want using system IO, which doesn't seem like the way to do it either.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Using ES3 Reader key not found exception

Post by Joel »

Hi there,

The error you are getting is because there is no save data in the cache with that filename. I.e.

Code: Select all

var settings = new ES3Settings(ES3.Location.Cache);
ES3.Save("myKey", 123, "myFile.es3", settings);

// This will not throw an error.
ES3.StoreCachedFile("myFile.es3");

// This will throw an error.
ES3.StoreCachedFile();

// And so will this.
ES3.StoreCachedFile("DifferentFileName.es3");
All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Frank
Posts: 5
Joined: Wed Mar 08, 2017 7:54 pm

Re: Using ES3 Reader key not found exception

Post by Frank »

I see, thanks! Got it working. I was confused by the paradigm, but it makes sense now.
Post Reply