Continue to different nodes programatically based on condition.

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
jlhacode
Posts: 77
Joined: Fri Jul 03, 2020 6:23 am

Continue to different nodes programatically based on condition.

Post by jlhacode »

Hi. I have a Success and a Fail node after showing a puzzle. A Success() function gets called if the user succeeds, and vice versa. What would be the best practice way to enter the correct node in each respective method? My continue Continue Button is set to "Always", which might be giving me problems, but I'm not sure.
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Continue to different nodes programatically based on condition.

Post by Tony Li »

Hi,

If the puzzle is part of the conversation, such as a riddle, then two links will be helpful:
If the puzzle happens externally from the conversation, and the conversation stays active but waits until the puzzle is done, then you can do something like this:

1. In a dialogue entry node, tell the conversation to wait until it receives a sequencer message. You can choose the message string; it's arbitrary. Maybe something like:
  • Sequence:

    Code: Select all

    SendMessage(Open,,Puzzle); // Call the Open() method on scripts on Puzzle GameObject
    WaitForMessage(DoneWithPuzzle) // Stay on this node until message "DoneWithPuzzle"
2. In the Success() function, set a Dialogue System variable and send the sequencer message:

Code: Select all

void Success()
{
    DialogueLua.SetVariable("SolvedPuzzle", true);
    Sequencer.Message("DoneWithPuzzle");
}
3. In the Failure() function, set a Dialogue System variable and send the sequencer message:

Code: Select all

void Success()
{
    DialogueLua.SetVariable("SolvedPuzzle", false);
    Sequencer.Message("DoneWithPuzzle");
}
4. Add an empty node after the node above. (See the 'Conversations Evaluate Conditions One Extra Level Ahead' note.) Set the Sequence to "Continue()" to simulate a continue button click and automatically move past the node.

5. Link the empty node to two nodes, each of whose Conditions fields checks the DS variable and goes down the success or failure path.
jlhacode
Posts: 77
Joined: Fri Jul 03, 2020 6:23 am

Re: Continue to different nodes programatically based on condition.

Post by jlhacode »

The solution mostly works, except for one hiccup. The dialogue doesn't progress forward automatically when the puzzle is finished, even after adding a WaitForMessage(Answered) sequence to the node that launches the puzzle. I'm calling Sequencer.Message("Answered"); in the success method.
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Continue to different nodes programatically based on condition.

Post by Tony Li »

If you're using continue buttons, change:

Code: Select all

WaitForMessage(Answered)
to:

Code: Select all

Continue()@Message(Answered)
jlhacode
Posts: 77
Joined: Fri Jul 03, 2020 6:23 am

Re: Continue to different nodes programatically based on condition.

Post by jlhacode »

Perfect solution, thank you sir!
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Continue to different nodes programatically based on condition.

Post by Tony Li »

Glad to help! :-)
Post Reply