Saving Quest States via Script

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
DrewThomasArt
Posts: 60
Joined: Thu Mar 24, 2022 12:07 am

Saving Quest States via Script

Post 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!
User avatar
Tony Li
Posts: 22140
Joined: Thu Jul 18, 2013 1:27 pm

Re: Saving Quest States via Script

Post 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.
DrewThomasArt
Posts: 60
Joined: Thu Mar 24, 2022 12:07 am

Re: Saving Quest States via Script

Post 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!
User avatar
Tony Li
Posts: 22140
Joined: Thu Jul 18, 2013 1:27 pm

Re: Saving Quest States via Script

Post by Tony Li »

Happy to help!
DrewThomasArt
Posts: 60
Joined: Thu Mar 24, 2022 12:07 am

Re: Saving Quest States via Script

Post 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.
User avatar
Tony Li
Posts: 22140
Joined: Thu Jul 18, 2013 1:27 pm

Re: Saving Quest States via Script

Post by Tony Li »

Hi,

Yup, that'll work!
Post Reply