About using save data in dialogue system

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
joeylu
Posts: 111
Joined: Sun May 17, 2020 1:07 pm

About using save data in dialogue system

Post by joeylu »

Hi Tony, our game is a narrative game that doesn't involves complicate data (at least for now).
So I'm thinking to use the PersistentDataManager.GetSaveData() and ApplySaveData() to save variables, I'm wondering what is the best way to achieve this.
My thoughts, I add a static Item in dialogue editor, for instance, name it slot_A, than whenever player hit the save button, I use GetSaveData() to gather all the variables into a string, then manually update that string to the slot_A value.
Next time when the player wants to load from those variables, I use DialogueLua.GetItemField() to retrieve the save data string and ApplySaveData().
Does above logic makes any sense? or do I have any other simple way to save/load variables? tks
User avatar
Tony Li
Posts: 22149
Joined: Thu Jul 18, 2013 1:27 pm

Re: About using save data in dialogue system

Post by Tony Li »

Hi,

That won't save anything to persistent storage. Consider using PlayerPrefs instead. Here are two methods to save and load the variables:

Code: Select all

public void SaveGame() {
    PlayerPrefs.SetString("SavedGame", PersistentDataManager.GetSaveData());
}

public void LoadGame() {
    if (PlayerPrefs.HasKey("SavedGame")){
        PersistentDataManager.ApplySaveData(PlayerPrefs.GetString("SavedGame"));
    } else {
        DialogueManager.ResetDatabase();
    }
}
Post Reply