End Conversation Button, Already Spoken Text, And Few More Questions

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
creativestorm
Posts: 10
Joined: Mon Mar 14, 2022 10:55 pm

End Conversation Button, Already Spoken Text, And Few More Questions

Post by creativestorm »

Great product and thank you for your continued support!

Few more questions as I am setting everything up with my project.

1) Custom Dialogue/Conversation Node Field: Is it possible for me to add a custom field to conversation nodes that I can reference from other scripts in the project?

2) Already Spoken Dialogue: Is there a way to change the NPC's greeting when going back to a conversation node. For example, if I have the NPC saying: "Hello there. My name is Max - how can I help you?", is it possible to replace/change that piece of dialogue to something else the next time you land on that conversation node, an example being: "Yes. What now?"

3) One-Time Use Toggle: Is there a quick and easy toggle option to close off a conversation node when going through it once? The only way I am currently aware is by setting a bool and blocking that conversation node once the bool is triggered - but I'm wondering if there is an easier way of toggling this instead.

4) Blocking/Hiding and Showing: Related to the previous question, I know how to block certain dialogue nodes. But with my current project, I have set it so that blocked dialogue nodes show up still as I want the player to see these (currently using that for gated skill checks) - so that's all good. But is there a way to show some blocked dialogue nodes and hide others (like a one-use only dialogue option, for example)?

5) Response Number: Which variable would I use to show the response number on it's own? In the response button prefab, I have created two TextMesh components instead of just one: one for the response and one for the response number (otherwise the spacing of the formatting is off depending on the size of the number).

6) End Conversation Button: Is it possible to add an End Conversation button to end the conversation instead of it ending automatically when hitting an End dialogue node? I have the Continue button working great, but if I can set up an additional button to end dialogue, that would be great.

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

Re: End Conversation Button, Already Spoken Text, And Few More Questions

Post by Tony Li »

Hi,
creativestorm wrote: Thu Mar 17, 2022 3:51 pm1) Custom Dialogue/Conversation Node Field: Is it possible for me to add a custom field to conversation nodes that I can reference from other scripts in the project?
Yes. Conversation nodes are called "dialogue entries" in the Dialogue System.
  • If you want to add a custom field to all dialogue entries, add it to the dialogue entry template in the Dialogue Editor's Templates section. Then select Menu > Apply Template To Assets.
  • If you only want to add it to a specific dialogue entry, inspect that entry. Expand All Fields, and add it there.
Custom dialogue entry fields are often checked in special Dialogue System methods such as OnConversationLine() and OnConversationResponseMenu(). Example:

Code: Select all

void OnConversationLine(Subtitle subtitle)
{
    if (Field.FieldExists(subtitle.dialogueEntry.fields, "Points"))
    {
        int points = Field.LookupInt(subtitle.dialogueEntry.fields, "Points");
        Debug.Log($"You earned {points} points by getting to this dialogue entry.");
    }
}
creativestorm wrote: Thu Mar 17, 2022 3:51 pm2) Already Spoken Dialogue: Is there a way to change the NPC's greeting when going back to a conversation node. For example, if I have the NPC saying: "Hello there. My name is Max - how can I help you?", is it possible to replace/change that piece of dialogue to something else the next time you land on that conversation node, an example being: "Yes. What now?"
Yes. Please see: How To: Run a Conversation Only Once. Briefly: Use a variable or SimStatus.
creativestorm wrote: Thu Mar 17, 2022 3:51 pm3) One-Time Use Toggle: Is there a quick and easy toggle option to close off a conversation node when going through it once? The only way I am currently aware is by setting a bool and blocking that conversation node once the bool is triggered - but I'm wondering if there is an easier way of toggling this instead.
No, that's the way to do it. A variable or SimStatus.
creativestorm wrote: Thu Mar 17, 2022 3:51 pm4) Blocking/Hiding and Showing: Related to the previous question, I know how to block certain dialogue nodes. But with my current project, I have set it so that blocked dialogue nodes show up still as I want the player to see these (currently using that for gated skill checks) - so that's all good. But is there a way to show some blocked dialogue nodes and hide others (like a one-use only dialogue option, for example)?
Please see: How To: Do Skill Checks in Conversations. That article has a link to another article that explains how to selectively show some invalid responses but not others.
creativestorm wrote: Thu Mar 17, 2022 3:51 pm5) Response Number: Which variable would I use to show the response number on it's own? In the response button prefab, I have created two TextMesh components instead of just one: one for the response and one for the response number (otherwise the spacing of the formatting is off depending on the size of the number).
The easy way: On your StandardUIMenuPanel, enable autonumbering, and set the Format to:

Code: Select all

{0}. <ident=10%>{1}</indent>
This will indent all responses to the same amount so they line up. (In the example above, it will indent all responses to 10% of the rect transform's width.)

The more complicated way: Make a subclass of StandardUIResponseButton that supports a separate number UI element. Then make a subclass of StandardUIMenuPanel that overrides SetResponseButton() to also set the number UI element's value.
creativestorm wrote: Thu Mar 17, 2022 3:51 pm6) End Conversation Button: Is it possible to add an End Conversation button to end the conversation instead of it ending automatically when hitting an End dialogue node? I have the Continue button working great, but if I can set up an additional button to end dialogue, that would be great.
At the end of the conversation, do you want to require the player to click the continue button and then click an end conversation button? Or do you want to show an end conversation button instead of the continue button?

In either case, nothing specific for that is built in. For the latter, you could set the continue button's text based on whether the current conversation state (DialogueManager.currentConversationState) has any responses or not.
creativestorm
Posts: 10
Joined: Mon Mar 14, 2022 10:55 pm

Re: End Conversation Button, Already Spoken Text, And Few More Questions

Post by creativestorm »

Thanks for the responses, much appreciated.

1) That worked. Thanks.

2) Thanks. The example provided only works for (as far as I can tell) coming back to a conversation. Is there a way though to have a dialogue node in the editor show an alternate Dialogue text if the "TalkedToNPC" condition is true. Meaning in the same conversation, if the person goes down one branch and then returns back to the main branch (via "I need to ask more questions") beneath start, instead of saying "Hello. My name is Max." it would say "How can I help you now?"

Here's an example of a branch where clicking on "More Questions" takes us back to the initial node where everything branches off from. It wouldn't be ideal for him to introduce himself there again:
Image

3) Makes sense, will look into these.

4) Thanks. I have this working after scouring previous forum posts. I added the StandardDialogueUIShowInvalidResponses.cs script to the Western RPG UI prefab (that is the one I am using), replacing the previous StandardDialogueUI.cs script there. These are now permanent fields I can change the booleans if required.

5) Thanks, I figured out a hack for this by just adding a counter every time a response button is instantiated and then referencing that number in the separate TextMesh component. I had to do this so that the number was perfectly centered in the diamond graphic.

6) If there is a way to universally call a c# script (I currently have one with my after-conversation housekeeping taken care of) every time at conversation ends (without having to attach it as a condition manually to end nodes), then I could in theory use the Continue button to end conversations while just changing the text component to say "End Conversation".
I'm not sure what setting I would use for the Continue button to show up at the end of the conversation (if that setting exists). It is currently set for "Not Before Response Menu" and is working fine for now - but I assume I would need to change that to have the additional functionality of showing up at conversation end and not closing the dialogue window automatically.

Here's an example of what I did for the game using a temporary dialogue window I put together previously (this is what comes up after I tell the person "goodbye":
Image
User avatar
Tony Li
Posts: 21980
Joined: Thu Jul 18, 2013 1:27 pm

Re: End Conversation Button, Already Spoken Text, And Few More Questions

Post by Tony Li »

Hi,
creativestorm wrote: Fri Mar 18, 2022 12:13 am2) Thanks. The example provided only works for (as far as I can tell) coming back to a conversation. Is there a way though to have a dialogue node in the editor show an alternate Dialogue text if the "TalkedToNPC" condition is true. Meaning in the same conversation, if the person goes down one branch and then returns back to the main branch (via "I need to ask more questions") beneath start, instead of saying "Hello. My name is Max." it would say "How can I help you now?"
Insert a Group node between <START> and the next nodes: Create an empty node, and tick its Group checkbox. Then link back to the Group node:

loopbackConv.png
loopbackConv.png (29.99 KiB) Viewed 374 times

The red questions marks indicate Conditions on the nodes. In the example above, they check a variable to decide which branch to take. The green arrow indicates a Script that sets the variable.

This next bit is probably overkill, so I'll put it in a spoiler block:
Conversation Position Stack
If you need to dip into a branch or another conversation and then return to your place prior to dipping into that branch, use the conversation position stack. Use PushConversationPosition() to save the current conversation state before following a different branch. At the end of that branch, use PopConversationPosition() to return to the saved conversation state.
creativestorm wrote: Fri Mar 18, 2022 12:13 am6) If there is a way to universally call a c# script (I currently have one with my after-conversation housekeeping taken care of) every time at conversation ends (without having to attach it as a condition manually to end nodes), then I could in theory use the Continue button to end conversations while just changing the text component to say "End Conversation".
Add a C# script with an OnConversationLine() method to the Dialogue Manager, or to the dialogue UI if you prefer and if it's going to be inside the Dialogue Manager's hierarchy (e.g., child of the Dialogue Manager's Canvas). In the method, check if we're at the end of the conversation. If so, show the continue button and tell the node to wait for a sequencer message from it. Example:

Code: Select all

using UnityEngine;
using UnityEngine.UI;
using PixelCrushers.DialogueSystem;

public class ShowEndConversationButton : MonoBehaviour
{
    public Button continueButton; // Assign in inspector, or get via code. In this example, assume inspector assignment.

    private void Start()
    {
        // Configure the button to send a sequencer message "End" in addition to its regular activity:
        continueButton.onClick.AddListener(() => { Sequencer.Message("End"); });
    }

    void OnConversationLine(Subtitle subtitle)
    {
        if (!DialogueManager.currentConversationState.hasAnyResponses)
        {
            // If we're at the end of the conversation, force the continue button to be visible with
            // the text END CONVERSATION. (assuming Text here, but you can switch to TextMeshProUGUI)
            continueButton.GetComponentInChildren<Text>().text = DialogueManager.GetLocalizedText("END CONVERSATION");
            continueButton.gameObject.SetActive(true);
            
            // Tell this line to wait for the sequencer message "End", which is sent by the continue button:
            subtitle.sequence = "WaitForMessage(End); " + subtitle.sequence;
        }
    }

    void OnConversationEnd(Transform actor)
    {
        // Set the continue button text back to CONTINUE:
        continueButton.GetComponentInChildren<Text>().text = DialogueManager.GetLocalizedText("CONTINUE");
        continueButton.gameObject.SetActive(false);
    }
}
creativestorm
Posts: 10
Joined: Mon Mar 14, 2022 10:55 pm

Re: End Conversation Button, Already Spoken Text, And Few More Questions

Post by creativestorm »

With regards to the End Conversation button, this is perfect! That works great.

I'll look into the Group node next.

Thanks Tony, much appreciated.
Post Reply