More on Conditions

Setting Conditions

You can add Lua expressions to a dialogue entry's Conditions field to only allow the conversation to use that entry if the Lua expressions are true.

For example, say you only want an NPC to say a line of dialogue if the player has visited Paris. You could define a variable "VisitedParis" (see Variables) whose initial value is false. When the player visits Paris, set the variable true. Then add a condition to the NPC's dialogue entry:

  • Dialogue Text: "So, what did you think of Paris?"
  • Condition: Variable["VisitedParis"] == true

You don't have to enter Lua expressions manually. You can use the Lua Wizards to build the conditions by selecting what you want from dropdown menus.

Additional Condition Features

If you need to perform additional checks outside of Lua, you can either register your own C# function with Lua (see Registering Functions) or use an IsDialogueEntryValid Delegate.

Conditions Are Ignored On START Node

Conditions are not checked on the conversation's START node.

SimStatus Conditions

If you want to track which dialogue entries have been used, for example to conditionally block them from being used again, use SimStatus. See How to Use SimStatus for more information.

Conversations Evaluate Conditions One Extra Level Ahead

The Dialogue System evaluates links one extra level ahead of the conversation. (It has to do this to properly handle certain continue button modes.) This means that if you set a value in one dialogue entry node (e.g., node A), you can't then check it in the next node (node B) because the Dialogue System will have already checked the condition of node B prior to running node A.

Instead, you need to separate them with an empty spacer node to delay evaluation of the condition.

To demonstrate this, we'll use an example conversation of flipping a coin:

In the example above, the "Flipping coin" node sets a variable x randomly to 1 or 2. We can't immediately follow this with the two conditional nodes ("Heads" and "Tails") because the Dialogue System evaluates one level ahead – meaning that it's already tested the conditions of "Heads" and "Tails" before the "Flipping coin" node has even run.

To work around this, we added an intermediate node to the conversation, set the Title to "delay evaluation" to remind ourselves what it's for, and left the Dialogue Text blank. Then we set the Sequence to None() so it will immediately progress to the next step in the conversation. (If you're using continue buttons, then on the Sequence field select "+" > Continue > Simulate continue button click instead of using None().)

When working with Conditions, it may also be helpful to temporarily set the Dialogue Manager's Debug Level to Info. This will add a lot of information to the Console window. If you pick through it, you'll find lines similar to the ones shown below:

Dialogue System: Lua(x = math.random(2))
Dialogue System: Referee says 'Flipping coin...'
Dialogue System: Block on False Link (Referee): ID=5:3 'Heads!' Condition='x == 1'
Dialogue System: Add Link (Referee): ID=5:4 'Tails!' (True)
Dialogue System: Referee says 'Tails!'

Lines 3-4 indicate that the link to 'Heads' is blocked because 'x==1' is false, but it's adding the link to 'Tails' (because 'x==2' is true).


<< Dialogue Database