Force Response Menu On Last Node Via Script

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
skyrevdev
Posts: 3
Joined: Sun Sep 22, 2024 12:18 pm

Force Response Menu On Last Node Via Script

Post by skyrevdev »

Hi,

I'm currently trying to setup a specific use case for the dialogue system. I currently have the following settings on the Dialogue Manager:

Show NPC Subtitles During Line (true)
Show NPC Subtitles with Response (true)
Show PC Subtitles During Line (true)
Continue Button (Optional Before Response Menu)
Always Force Response Menu (false)

With this, both the player and NPCs will show their subtitles along with a continue button afterwards. If the player has more than 1 response, then it will skip the continue button and immediate show the response menu instead. This behavior is exactly how I want it, but there is one thing that I would like to change.

I would like to set the last conversation node to always show the response menu. Currently, the last node just shows the continue button. I found that you can add the [f] markup tag on this node, to simulate this behavior. However, I want this to be the default behavior, so I was wondering how I can change this via code, or if there were other options that I have missed to accomplish the same behavior.
User avatar
Tony Li
Posts: 22049
Joined: Thu Jul 18, 2013 1:27 pm

Re: Force Response Menu On Last Node Via Script

Post by Tony Li »

Hi,

Assuming you're using DS v2.2.47+ and the Dialogue Manager's Other Settings > Reevaluate Links After Subtitle is ticked, you can add an OnConversationLine(Subtitle) method to a script on the Dialogue Manager. Something like this should work:

Code: Select all

void OnConversationLine(Subtitle subtitle)
{
    // Check if this node is followed by only one PC node and no NPC nodes:
    if (DialogueManager.currentConversationState.pcResponses.Length == 1 &&
        !DialogueManager.currentConversationState.hasNPCResponse)
    {
        // If so, get the state of that PC node:
        var nextState = DialogueManager.conversationModel.GetState(DialogueManager.currentConversationState.pcResponses[0].destinationEntry, includeLinks:true, skipExecution:true);
        // If it's the end, force it as a response menu by adding [f]:
        if (!nextState.hasAnyResponses)
        {
            var nextEntry = nextState.subtitle.dialogueEntry;
            if (!nextEntry.currentDialogueText.Contains("[f]")) nextEntry.currentDialogueText += "[f]";
        }
    }
}
(Note: I just typed that in here. It may have typos or logic errors.)


Maybe related: How To: Set Continue Button Label to Continue or End
skyrevdev
Posts: 3
Joined: Sun Sep 22, 2024 12:18 pm

Re: Force Response Menu On Last Node Via Script

Post by skyrevdev »

Thanks for the reply! I had to update to the new version to get the new checkbox option. I then added your code to the dialogue manager by changing the following line:

Code: Select all

var nextState = DialogueManager.conversationModel.GetState(DialogueManager.currentConversationState.pcResponses[0].destinationEntry, includeLinks: true, skipExecution: true);
However, the behavior didn't seem to change after some testing (it still shows the continue button). I did some debugging to see if it was actually triggering, and I can see that it does add the markup tag to the last node's text. I was wondering if you had any other insight.

Also, as a side question, I noticed that the response menu pops up immediately while the subtitles are still typing out the dialogue text. However, the continue button waits until the subtitle text is finished. Is there a way to set the response menu to match that same behavior (wait until the dialogue is finished typing)?
User avatar
Tony Li
Posts: 22049
Joined: Thu Jul 18, 2013 1:27 pm

Re: Force Response Menu On Last Node Via Script

Post by Tony Li »

There was a bug in 2.2.47 that was fixed in 2.2.48, which is pending release on the Asset Store. Here's a patch from 2.2.48:

DS_ConversationControllerPatch_2024-09-23.unitypackage

Here's an example scene:

DS_ForceMenuLastResponseExample_2024-09-23.unitypackage
Post Reply