Page 1 of 1

Saving Quest States via Script

Posted: Sun Jan 01, 2023 12:48 am
by DrewThomasArt
I've been using a Saver script to save most of my data (coins, health, level, etc). But as for quest states, I've just been using the Dialogue System Saver component on my Dialogue Manager.

I'm now making it so players make an account and log in to play, and I'm saving their data on the online PlayFab backend servers. I'll be able to figure out how to save almost everything, except I don't know how to save the Quest States because that's done automatically via the Dialogue System Saver component.

A short version of my Saver script that I got from a tutorial on this website:

Code: Select all

public override string RecordData()
    {
       var data = new SaveData();
        data.currentHealth = GetComponent<PlayerHealth>().currentHealth;
        return SaveSystem.Serialize(data); 
    }
    
    public override void ApplyData(string s)
    {
       if (string.IsNullOrEmpty(s)) return; // If we didn't receive any save data, exit immediately.
        var data = SaveSystem.Deserialize<SaveData>(s);
        if (data == null) return; 
        Debug.Log($"Restoring currentHealth={data.currentHealth}");
             GetComponent<PlayerHealth>().healthBar.SetHealth(data.currentHealth);
      

    }
Any help will be greatly appreciated!

Re: Saving Quest States via Script

Posted: Sun Jan 01, 2023 8:31 am
by Tony Li
Hi,

See How To: Use Save System with other save system assets

It explains how to get the entire saved game data (custom savers as well as Dialogue System Saver) as a string that you can store in Playfab.

Re: Saving Quest States via Script

Posted: Sun Jan 01, 2023 6:19 pm
by DrewThomasArt
Tony Li wrote: Sun Jan 01, 2023 8:31 am Hi,

See How To: Use Save System with other save system assets

It explains how to get the entire saved game data (custom savers as well as Dialogue System Saver) as a string that you can store in Playfab.
I'm looking at all of the data stored online, it's very cool. So far it's working like a charm, thank you!

Re: Saving Quest States via Script

Posted: Sun Jan 01, 2023 8:17 pm
by Tony Li
Happy to help!

Re: Saving Quest States via Script

Posted: Sun Jan 01, 2023 9:42 pm
by DrewThomasArt
Tony Li wrote: Sun Jan 01, 2023 8:17 pmHappy to help!
I think this is the last issue, I can see all of the data being stored, and it's being recovered when the player hits "Continue" on the main menu, but it's not loading the scene automatically like it did when I used "PixelCrushers.SaveSystem.LoadFromSlot(0)"

I can see that the scene is saved, so the information is there, I just don't know how to load it at the same time the data is received. Is there a line of code or method I can call to load the scene?

This is how the data is recovered from the online database:

Code: Select all

public void GetSaveGame()
{
    PlayFabClientAPI.GetUserData(new GetUserDataRequest(), OnDataReceieved, OnError);
}

void OnDataReceieved(GetUserDataResult result)
{
Debug.Log("Recieved user data!");
if (result.Data != null && result.Data.ContainsKey("Player"))
{
    string data = (result.Data["Player"].Value);
    SaveSystem.ApplySavedGameData(SaveSystem.Deserialize<SavedGameData>(data));
} else 
{
    Debug.Log("Player data not complete!");
}
}
EDIT: Actually I think I solved it by adding this line when I recover the data,
"SaveSystem.LoadGame(SaveSystem.Deserialize<SavedGameData>(data));"

I'm assuming this is the correct way to do it, if so, I'm all set, and thanks again.

Re: Saving Quest States via Script

Posted: Mon Jan 02, 2023 7:37 am
by Tony Li
Hi,

Yup, that'll work!