Page 1 of 1

About using save data in dialogue system

Posted: Thu Mar 17, 2022 7:23 am
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

Re: About using save data in dialogue system

Posted: Thu Mar 17, 2022 9:40 am
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();
    }
}