Conversation conditions not working

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
farazk86
Posts: 26
Joined: Sun Feb 26, 2023 9:13 am

Conversation conditions not working

Post by farazk86 »

Hi there,

I have followed the tutorial:

to add conditions to my conversations, but its not working as shown in the video.

I have added a variable "kaahlerKilled" to the variables tab, and then in a conversation, based on the decision taken by the player the variable is set true or false:
Screenshot 2024-01-13 at 23.02.22.png
Screenshot 2024-01-13 at 23.02.22.png (98.26 KiB) Viewed 73825 times
But it appears that whatever I choose here the variable stays at its starting value of false and does not change..

Because when I use that as a condition the "false" path is always taken.. here is a screenshot of such a conversation:
Screenshot 2024-01-13 at 23.06.27.png
Screenshot 2024-01-13 at 23.06.27.png (147.8 KiB) Viewed 73825 times
But in the true path if I select: "false condition action = passthrough" then the true path is taken but the first conversation block is passed/ignored
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Conversation conditions not working

Post by Tony Li »

Hi,

What are the values of the Script fields on "Punish him" and "Forgive him"?

What are the Conditions on "General Akur, what has..." and "Prince Kaahler: I could li..."?

Please also see the video below. It shows how to check variable values at runtime:

farazk86
Posts: 26
Joined: Sun Feb 26, 2023 9:13 am

Re: Conversation conditions not working

Post by farazk86 »

The script field for "Punish him" is ``Variable["kaahlerKilled"] = true`` and the script field for "Forgive him" ``Variable["kaahlerKilled"] = false``.

The conditions of "General Akur, what has become," is ``Variable["kaahlerKilled"] == true``. And the conditions of "Prince Kaahler,..." is ``Variable["kaahlerKilled"] == false``.

I checked the video and tried the variable inspector during the dialogue and when Punish him was selected the runtime value changed from false to true.

But when the scene changed, the value went back to its initial value of false...
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Conversation conditions not working

Post by Tony Li »

farazk86 wrote: Sun Jan 14, 2024 3:03 amBut when the scene changed, the value went back to its initial value of false...
I think this is the key.

Did you untick the Dialogue Manager's Other Settings > Don't Destroy On Load checkbox?

How are you changing scenes? If you're not allowing the Dialogue Manager to survive scene changes, you must change scenes using the save system and DialogueSystemSaver component.
farazk86
Posts: 26
Joined: Sun Feb 26, 2023 9:13 am

Re: Conversation conditions not working

Post by farazk86 »

I would rather the dialogue manager not be persistent and it does not need to exist in every scene of my game, only in a couple cutscene scenes and in the campaign map scene. That is why I would rather it not be DontDestroyOnLoad().

Rather than use the save system (which is also persistent) can I not call a function in c# to save the variable? and then load this variable in in the campaign map scene?

I am changing scenes via the default SceneManager.

Thanks
farazk86
Posts: 26
Joined: Sun Feb 26, 2023 9:13 am

Re: Conversation conditions not working

Post by farazk86 »

I believe I found my answer in : https://pixelcrushers.com/dialogue_syst ... pting.html

I am saving the decision to a PlayerPref and then in the Awake() of my campaign map scene I am setting variable like:

Code: Select all

int kaahlerKilled = PlayerPrefs.GetInt("kahler_killed", 0);
        if (kaahlerKilled == 1)
            DialogueLua.SetVariable("kaahlerKilled", true);
        else
            DialogueLua.SetVariable("kaahlerKilled", false);
it seems to have done the trick :)
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Conversation conditions not working

Post by Tony Li »

I'm glad you got that working. It might not be very scalable, though. There's no reason to save a copy of the variable to PlayerPrefs and then restore it from PlayerPrefs. This also won't work on platforms (some consoles) that don't support PlayerPrefs. If you'd like to look into why variables aren't persisting across scene changes, please start by answering the questions above.
Post Reply