Saving or loading variable in conversation

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Kaliban
Posts: 4
Joined: Mon Feb 28, 2022 5:28 am

Saving or loading variable in conversation

Post by Kaliban »

Hello

I am totaly lost with the save system :c i just want to save and load simple variables across conversations but i can't figure out how it works

I'm using the GameSaver component for saving the variables in the conversations and made two simple methods for calling SaveGame() and LoadGame() from the GameSaver component. During the conversation i use SendMessage(NameOfTheMethod,,DialogueManager) in the Sequence thing, and there are no warnings. BUT each time i restart the conversation, the variable are reset to their initial state (i tracked these variable during the conversation and the values did change).

if i did something wrong what is the correct way for saving/loading these variable easily ?

thanks
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Saving or loading variable in conversation

Post by Tony Li »

Hi,

Are these Dialogue System variables, as in variables that you've added to your dialogue database in the Dialogue Editor's Variable section? If so, and if you don't want to use the whole save system, then configure your SaveGame() and LoadSave() similarly to this:

Code: Select all

void SaveGame()
{
    string savedVariables = PixelCrushers.DialogueSystem.PersistentDataManager.GetSaveData();
    // (Now you need to save the string. For example:)
    PlayerPrefs.SetString("Variables", savedVariables);
}

void LoadGame()
{
    if (PlayerPrefs.HasKey("Variables"))
    {
        string savedVariables = PlayerPrefs.GetString("Variables");
        PixelCrushers.DialogueSystem.PersistentDataManager.ApplySaveData(savedVariables);
    }
    else
    {  // (We don't have any save data, so just reset to initial state:)
        PixelCrushers.DialogueSystem.DialogueManager.ResetDatabase();
    }
}

If you need to save your own variables that you've defined in a C# script, you can use the full save system. In this case, write a custom saver.
Kaliban
Posts: 4
Joined: Mon Feb 28, 2022 5:28 am

Re: Saving or loading variable in conversation

Post by Kaliban »

Thanks a lot for your help !!! it works !
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Saving or loading variable in conversation

Post by Tony Li »

Glad to help!
Post Reply