Page 1 of 1

Only Save Variables

Posted: Mon Oct 26, 2020 4:25 am
by boz
Howdy,

I just want to save the variables in my Dialogue Database between loads/scenes.

In the documentation it says:
If you only want to save the state of the dialogue database (e.g., dialogue database variables, quest states, and SimStatus), you can bypass the Save System and use PixelCrushers.DialogueSystem.PersistentDataManager instead:

Code: Select all

string s = PersistentDataManager.GetSaveData(); // Save state.
PersistentDataManager.ApplySaveData(s); // Restore state.
DialogueManager.ResetDatabase(DatabaseResetOptions.KeepAllLoaded); // Reset state.
Is there more to it than this?

In a script attached to the Dialogue Manager I put:

Code: Select all

    string s;

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.S))
        {
            s = PersistentDataManager.GetSaveData(); // Save state.
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            PersistentDataManager.ApplySaveData(s); // Restore state.
        }
    }
When I test this, the variables still seem to be unaffected by the save/load.

I feel like I'm missing something here.

Thanks for any help :D

Re: Only Save Variables

Posted: Mon Oct 26, 2020 9:21 am
by Tony Li
Hi,

That should work. Are you changing any variable value between press 'S' and 'C'?

Are there any errors or warnings in the Console?

Re: Only Save Variables

Posted: Mon Oct 26, 2020 3:33 pm
by boz
You know what? I just checked the dialogue variable I was testing and it was being set via my script rather than by the dialogue system, so it would've been reset every time.

Good to know it should work, though! I'll do a better test.

This is a load off, thanks :)

Re: Only Save Variables

Posted: Mon Oct 26, 2020 3:47 pm
by Tony Li
Glad you got to the bottom of it!

Re: Only Save Variables

Posted: Mon Oct 26, 2020 5:40 pm
by boz
So I was just testing and it did work if I want to return the variable to a previous state, but it didn't work for my intended use-case, which is to be able to return all the variables to their saved state when you reload the game. Does this not work for that use-case? Or am I messing it up still?

Re: Only Save Variables

Posted: Mon Oct 26, 2020 7:56 pm
by Tony Li
PersistentDataManager.ApplySavedGameData(s) should restore the Lua Variable[] array to the state that was recorded by PersistentDataManager.GetSavedGameData().

What's happening instead?

Are there any errors or warnings in the Console window?

Re: Only Save Variables

Posted: Mon Oct 26, 2020 11:26 pm
by boz
I finally got it, but I don't know if I did it right.

I noticed that it was saving all the data to a string variable which was getting erased every time I restarted the game, so I had my own save system save that string and then feed it back in and all was well.

I guess I was hoping it would magically take care of all of that for me :oops:

Re: Only Save Variables

Posted: Tue Oct 27, 2020 8:20 am
by Tony Li
Hi,

The full save system would take care of it. But since you're only using PersistentDataManager.GetSaveData() and ApplySaveData(), it simply returns a string (which you must save on your own) and restores the variables from the string (which you must load and provide).