Showing variable value issue

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

Showing variable value issue

Post by Kaliban »

Hello

for the sake of understanding here is the test conversation tree that i use :
Tree.PNG
Tree.PNG (22.32 KiB) Viewed 190 times
the problem i have is if i put a "SendMessage(PersoLoadGame,,DM)" in the node 01 and then put "Tyran= [var = Tyran]" in the nodes 02 and 07, then the variable value is correct on the node 07 but not in the node 02. In 02 it show the default value in the Variable's section of the editor

BUT

when doing the SAME except putting the sequence command in the start node, then even in the node 02 i have the correct value .... and i don't know why

it's not a big problem but it can be one if i don't understand why, maybe i'm doing something wrong ?

PS : I'm also using a savegame command in the sequence of the last node in order to save the variables values
and the save and load methods are the follows:

Code: Select all

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

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

        }
    }
User avatar
Tony Li
Posts: 21980
Joined: Thu Jul 18, 2013 1:27 pm

Re: Showing variable value issue

Post by Tony Li »

Hi,

When 01's Sequence contains only "SendMessage(PersoLoadGame,,DM)", it will end immediately, move to 02 on the same frame. PersoLoadGame() will also be called on that frame, so you can get into a race condition where PersoLoadGame() and preparing the text for 02 can run in either order. Your solution to put the sequencer command one node earlier will work. Or you can give node 01 time to finish its SendMessage() call before moving to 02 by setting the Sequence to something like: "SendMessage(PersoLoadGame,,DM); Delay(0.2)". (I prefer moving it one node earlier. I think it's cleaner.)
Kaliban
Posts: 4
Joined: Mon Feb 28, 2022 5:28 am

Re: Showing variable value issue

Post by Kaliban »

Aw ok, it's way simpler than i thought

thanks a lot again, good day to you !
User avatar
Tony Li
Posts: 21980
Joined: Thu Jul 18, 2013 1:27 pm

Re: Showing variable value issue

Post by Tony Li »

Happy to help!
Post Reply