code doesn't process after I use ES3... ? I think?

Discussion and help for Easy Save 3
ariza8627
Posts: 16
Joined: Sun Jul 07, 2019 8:06 pm

Re: code doesn't process after I use ES3... ? I think?

Post by ariza8627 »

Hey Joel. So I don't know how to profile the ES3.Save method in specific, but attached is the profile of the game's scripts.
~ashenAlex
Attachments
I hope this will suffice. If not, just let me know. Thanks.
I hope this will suffice. If not, just let me know. Thanks.
profiler2.png (73.95 KiB) Viewed 2713 times
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: code doesn't process after I use ES3... ? I think?

Post by Joel »

Hi there,

Unfortunately this doesn't give me the information I require. Please could you PM me a basic project which replicates this issue and instructions to replicate it?

I would also try going to Window > Easy Save 3 > Tools > Open Persistent Data Path, and delete your save data and see if that fixes the issue. It may be that you have left over data from previous testing in there, causing the load times to become longer.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: code doesn't process after I use ES3... ? I think?

Post by Joel »

Thanks for the PM, I understand now. I previously I thought you meant that a single ES3.Save call caused a 6-second delay.

In this case the slowdown is caused for two reasons:
  1. Every time you load, a file has to be opened and closed, which is an expensive operation
  2. There is a large number of keys in your file, so there is also overhead for random access
To remove this overhead, we provide the ES3File class. This caches the data so that you only need to open a file once, and it uses a Dictionary to handle random access, which is relatively fast.

However, there's an even easier way. It looks like all of the fields of your class are supported types, so you can simply save your BaseStats class, rather than saving each of it's variables individually. I.e. assuming your class is named BaseStats:
ES3.Save<BaseStats>("_BaseStats", _BaseStats);
_BaseStats = ES3.Load<BaseStats>("_BaseStats");
All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
ariza8627
Posts: 16
Joined: Sun Jul 07, 2019 8:06 pm

Re: code doesn't process after I use ES3... ? I think?

Post by ariza8627 »

I've been trying to figure this one out...
if I were to save the whole class in one variable, how would i load specific variables back into the game?
Still however, I did try to do ES3.Save<BaseStats>("_BaseStats", _BaseStats);, but it didn't like the syntax. The _BaseStats class is a static class, if that matters at all.
~ashenAlex
ariza8627
Posts: 16
Joined: Sun Jul 07, 2019 8:06 pm

Re: code doesn't process after I use ES3... ? I think?

Post by ariza8627 »

ok I guess I understand how you could have each variable saved and then loaded back again but thats kinda wild. I mean, i would guess that when i save the class, each variable is saved and when i make the class = the saved directory of the class, each variable would be set equal to their past value, right? anyways, i would like to create a way for the user to have a maximum of 3 profiles. actually, ive basically done this already. and i can think of a way to make this all work, i actually have a variable in place right now to signify which profile the user is using to then load the values from only that profile. the only thing is, i dont know how to save the entire class and it would be nice to figure that out. if it is impossible for me to save references to variables, i dont understand how i would save an entire class in one call. thanks for helping!
~ashenAlex
Attachments
the error i get when i try to save the _BaseStats class...
the error i get when i try to save the _BaseStats class...
game.png (212.06 KiB) Viewed 2704 times
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: code doesn't process after I use ES3... ? I think?

Post by Joel »

Hi there,

My apologies, I wasn't aware that your class was static. In this case it's not possible to serialise it as a class as it's not possible to get an instance of it to load into.

In this case there's two options:

1. Save each variable separately and use an ES3File (as described before) to maximise performance.
2. Or turn your static class into a singleton, and then save the instance.

If you decided to go the singleton route, you could save and load it as follows:
ES3.Save<BaseStats>("BaseStats", BaseStats.Instance);
BaseStats.Instance = ES3.Load<BaseStats>("BaseStats");
Just incase you need help turning your class into a singleton, it would look like this:
public class BaseStats
{
    private static BaseStats _instance = null;
    public static BaseStats Instance
    {
        get
        { 
            if(_instance == null)
                _instance = new BaseStats();
            return _instance;
        }
        set { _instance = value; }
    }
    
    public float playerHealth = 100;
    public string introText = "introText";
    // Etc
}
Hope this helps!

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
ariza8627
Posts: 16
Joined: Sun Jul 07, 2019 8:06 pm

Re: code doesn't process after I use ES3... ? I think?

Post by ariza8627 »

Awesome. And it figures that if the class is static, I can't use it the same as a non static one, that's how most things are so yea, i just figured you just didnt assume the class was static in the first place. But always have I thought about being able to make my _BaseStats class a non static one. This is a lot to ask, but is there any way that you could tell me the correct way to create reference variables so I can call other variables in that referenced class?
Thanks
~ashenAlex
ariza8627
Posts: 16
Joined: Sun Jul 07, 2019 8:06 pm

Re: code doesn't process after I use ES3... ? I think?

Post by ariza8627 »

correction: possibly it may help to know that the _BaseStats class itself is not static but all of the variables inside of it are.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: code doesn't process after I use ES3... ? I think?

Post by Joel »

ariza8627 wrote:correction: possibly it may help to know that the _BaseStats class itself is not static but all of the variables inside of it are.
Ah, this I can work with :)

By default Easy Save will ignore static variables when serialising. However, I'll PM you an update which tells Easy Save to automatically serialise these. Then you can save and load an instance of the class, and the static variables will also be stored. I.e.
ES3.Save<BaseStats>("myKey", new BaseStats());
ES3.Load<BaseStats>("myKey");
All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
ariza8627
Posts: 16
Joined: Sun Jul 07, 2019 8:06 pm

Re: code doesn't process after I use ES3... ? I think?

Post by ariza8627 »

Just sent you a PM.
Thank you for all your help!
I'm just an 18 year old fresh out of high school who dreams of contributing to the gaming industry with my first release.
I will let you know if I have any more questions but as I said in the PM, everything is working just fine as of now.
Thank you, Joel!
Post Reply