Saving from Cache to specific file path?
Saving from Cache to specific file path?
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!
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!
Re: Saving from Cache to specific file path?
Hi there,
ES3.StoreCachedFile accepts a filePath parameter. So if you save data to the cache using:
You can store that cached file using:
All the best,
Joel
ES3.StoreCachedFile accepts a filePath parameter. So if you save data to the cache using:
Code: Select all
ES3.Save("myKey", myValue, "myFileName.es3");
Code: Select all
ES3.StoreCachedFile("myFileName.es3");
Joel
Re: Saving from Cache to specific file path?
Hi Joel,
Thanks for the quick response! However I still don't understand how this would work...
Doesn't the line
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
Which makes me think that "settings" is the only argument that will lead to saving to the cache, in this example.
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");
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);
Re: Saving from Cache to specific file path?
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
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
Re: Saving from Cache to specific file path?
As per your recommendation I've changed the Tools > Easy Save 3 > Settings -> Location to "Cache"
My save code is:
then, when I'm loading that save game:
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...
My save code is:
Code: Select all
ES3.Save<int>("myFavInt", 42, saveSlotFileString);
ES3.StoreCachedFile(saveSlotFileString);
Code: Select all
int foo = ES3.Load<int>("myFavInt", saveSlotFileString);
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...
Re: Saving from Cache to specific file path?
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
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
Re: Saving from Cache to specific file path?
Ok, I think I've got this working, but would love confirmation that this is indeed utilizing the cache correctly.
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?
Code: Select all
var settings = new ES3Settings(ES3.Location.Cache);
ES3.Save<int>("myFavInt", 42, "Slot1.es3", settings);
ES3.StoreCachedFile( "Slot1.es3");
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?
Re: Saving from Cache to specific file path?
That is correct
All the best,
Joel
All the best,
Joel