Saving from Cache to specific file path?

Discussion and help for Easy Save 3
Post Reply
Pil.0
Posts: 4
Joined: Fri Jan 29, 2021 10:30 pm

Saving from Cache to specific file path?

Post by Pil.0 »

I'm trying to refactor my save code to use the technique outlined on the Improving Performance page but I'm hitting a snag. I can't figure out how to save to a specific file path with this method.

The user is allowed to save in three separate save slots, which I'm storing as 3 separate files. Prior to using the cache, I would use a line like...

ES3.Save<int>("myFavInt", 42, saveSlotString);

Where "saveSlotString" might contain the string "Slot1.es3", "Slot2.es3" or "Slot3.es3" which I would assign prior to this line. How would I do something similar with the ES3.StoreCachedFile() function?

It seems like something to do with the ES3Settings argument but I can't figure out how to make it work for my use case. Thanks in advance!
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving from Cache to specific file path?

Post by Joel »

Hi there,

ES3.StoreCachedFile accepts a filePath parameter. So if you save data to the cache using:

Code: Select all

ES3.Save("myKey", myValue, "myFileName.es3");
You can store that cached file using:

Code: Select all

ES3.StoreCachedFile("myFileName.es3");
All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Pil.0
Posts: 4
Joined: Fri Jan 29, 2021 10:30 pm

Re: Saving from Cache to specific file path?

Post by Pil.0 »

Hi Joel,

Thanks for the quick response! However I still don't understand how this would work...

Doesn't the line

Code: Select all

ES3.Save("myKey", myValue, "myFileName.es3");
Save directly to the file, and not the cache? This was what my original code looked like.

I believe my confusion is coming from the "Improving Performance" page where it states

Code: Select all

// Create an ES3Settings to save to and load from the cache.
var settings = new ES3Settings(ES3.Location.Cache);
// Save to the cached file.
ES3.Save("myInt", 123,  settings);
Which makes me think that "settings" is the only argument that will lead to saving to the cache, in this example.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving from Cache to specific file path?

Post by Joel »

Hi there,

I assumed that you had set the storage location to Cache in Tools > Easy Save 3 > Settings.

If not, you will need to provide the ES3Settings object to save to the cache (which is the fourth parameter).

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Pil.0
Posts: 4
Joined: Fri Jan 29, 2021 10:30 pm

Re: Saving from Cache to specific file path?

Post by Pil.0 »

As per your recommendation I've changed the Tools > Easy Save 3 > Settings -> Location to "Cache"

My save code is:

Code: Select all

ES3.Save<int>("myFavInt", 42, saveSlotFileString);
ES3.StoreCachedFile(saveSlotFileString);
then, when I'm loading that save game:

Code: Select all

int foo = ES3.Load<int>("myFavInt", saveSlotFileString);
This works at run time, but it doesn't seem to save to a permanent file- when I close the game and restart it, I am unable to load the save. This configuration only seems to save and load during uninterrupted runtime.

To reiterate, my goal is to use the technique on the "Improving Performance" page so I can save to 1 of 3 specific file paths/save slots, to be loaded in future sessions when the player resumes the game.

Apologies for my lack of understanding here...
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving from Cache to specific file path?

Post by Joel »

Hi there,

You don't appear to be calling ES3.CacheFile(yourFileName). This loads the file from storage into the cache, as described in the Improving Performance guide.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Pil.0
Posts: 4
Joined: Fri Jan 29, 2021 10:30 pm

Re: Saving from Cache to specific file path?

Post by Pil.0 »

Ok, I think I've got this working, but would love confirmation that this is indeed utilizing the cache correctly.

Code: Select all

var settings = new ES3Settings(ES3.Location.Cache);
ES3.Save<int>("myFavInt", 42, "Slot1.es3", settings);
ES3.StoreCachedFile( "Slot1.es3");
The element I was missing/not understanding was that I could use the 4th parameter so the call would include the file path as well as the cache ES3Settings.

So, for example, if I save 100 different values using many different ES3.Save calls in this format, I would still only make one file write with the ES3.StoreCachedFile(saveSlotFileString). Is that correct?
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving from Cache to specific file path?

Post by Joel »

That is correct :)

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