Combine two Dialogue Entries into a single sentence

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
bohemian pulp
Posts: 21
Joined: Wed Apr 21, 2021 7:01 am

Combine two Dialogue Entries into a single sentence

Post by bohemian pulp »

Hello everybody!

I wondered if there is a way to combine two Dialogue Entries into a single sentence so that I could have different endings depending on conditions.

For example:
1. Starting entry: "I want to go"
2. entry 1: "camping."
3. entry 2: "fishing."

So if a character said sometime before that he likes fishing, it would automatically write: "I want to go fishing." as a single sentence. I am aware I could do it with variables, but combining would fit so much more. There was a similar thing in Inkle, and, weirdly, there is no option like this for UDS. Or I'm missing it? I tried adding Continue(), but then it doesn't display the subtitle. That's another question, by the way. Is there a way to sequence a continue button press and also show the text?

I'm sorry if this is a duplicate topic. I searched and couldn't find anything on this.
Creator of "Let Bions be bygones"
https://linktr.ee/bohemianpulp
User avatar
Tony Li
Posts: 22037
Joined: Thu Jul 18, 2013 1:27 pm

Re: Combine two Dialogue Entries into a single sentence

Post by Tony Li »

Hi,

There isn't a way to do exactly that without a little scripting. But you could use a group node to group those entries:

campingOrFishing.png
campingOrFishing.png (11.27 KiB) Viewed 755 times

To sequence the continue button, use the Continue() sequencer command. For example, to simulate a continue button click after 3 seconds, set the entry's Sequence field to:

Code: Select all

Continue()@3
User avatar
bohemian pulp
Posts: 21
Joined: Wed Apr 21, 2021 7:01 am

Re: Combine two Dialogue Entries into a single sentence

Post by bohemian pulp »

Thanks for the answer, mate!

I wasn't using the groups, I'll add them to my workflow, unfortunately, that doesn't help. :(

Continue()@2 is also something I didn't use, it almost does the job, but it's still in two lines, and I'd like it to be a single uninterrupted sentence.
2021-04-22 13_28_17-Window.png
2021-04-22 13_28_17-Window.png (3.27 KiB) Viewed 750 times
Maybe I want to build it from for example:
1. I would like / I want / I was going
2. to go / to spend time
3. camping / fishing / relaxing

It would be a lot of variables to handle that, and only a couple of conditions if it would print the text as a single sentence without breaking every entry.
Creator of "Let Bions be bygones"
https://linktr.ee/bohemianpulp
User avatar
Tony Li
Posts: 22037
Joined: Thu Jul 18, 2013 1:27 pm

Re: Combine two Dialogue Entries into a single sentence

Post by Tony Li »

Hi,

Note that the group node ( {group}<I want to go...> ) doesn't actually contribute any text to the conversation. It's just a grouping mechanism. The two nodes that it links to ("I want to go camping" and "I want to go fishing") contain the complete text for the sentence.

Since this is outside the regular purview of the way Dialogue System conversation trees work, if you don't want to use group nodes then you could use a little supplemental scripting. Let's say you write your conversation like this:

accumulateText.png
accumulateText.png (10.13 KiB) Viewed 749 times

You could add a script to the Dialogue Manager that has an OnConversationLine method. This method can check if the current line ends with the string "[...]". If so, it can accumulate that text to be shown later instead of showing it now. Here's a rough example (typed directly in here; may have typos):

HandleAccumulatedText.cs

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class HandleAccumulatedText : MonoBehaviour
{
    private string accumulatedText;
    
    void OnConversationLine(Subtitle subtitle)
    {
        if (subtitle.formattedText.text.EndsWith("[...]"))
        {
            // Accumulate this text instead of showing it:
            accumulatedText += subtitle.formattedText.text.Replace("[...]", string.Empty);
            subtitle.formattedText.text = string.Empty;
            subtitle.sequence = "Continue()";
        }
        else
        {
            // This line doesn't have [...], so prepend any accumulated text:
            if (!string.IsNullOrEmpty(accumulatedText))
            {
                subtitle.formattedText.text = accumulatedText + subtitle.formattedText.text;
                accumulatedText = string.Empty;
            }
        }
    }
}
(Edit: Added "using" statements.)
User avatar
bohemian pulp
Posts: 21
Joined: Wed Apr 21, 2021 7:01 am

Re: Combine two Dialogue Entries into a single sentence

Post by bohemian pulp »

Awesome!

I'll tinker with it, and let you know what I ended up with :)

Thanks again for the support!
Creator of "Let Bions be bygones"
https://linktr.ee/bohemianpulp
User avatar
bohemian pulp
Posts: 21
Joined: Wed Apr 21, 2021 7:01 am

Re: Combine two Dialogue Entries into a single sentence

Post by bohemian pulp »

It says this:

Code: Select all

Assets\Dialogue System Examples\HandleAccumulatedText.cs(9,29): error CS0246: The type or namespace name 'Subtitle' could not be found (are you missing a using directive or an assembly reference?)
I'm not a coder, so I have no idea what to do to fix it :?
Creator of "Let Bions be bygones"
https://linktr.ee/bohemianpulp
User avatar
Tony Li
Posts: 22037
Joined: Thu Jul 18, 2013 1:27 pm

Re: Combine two Dialogue Entries into a single sentence

Post by Tony Li »

Hi,

I omitted some things for brevity. I just added the "using" statements at the top of the code in my previous reply. That should resolve the errors.
User avatar
bohemian pulp
Posts: 21
Joined: Wed Apr 21, 2021 7:01 am

Re: Combine two Dialogue Entries into a single sentence

Post by bohemian pulp »

Works like a charm!
Untitled-1.jpg
Untitled-1.jpg (51.44 KiB) Viewed 744 times
You should definitely add this to extras if not integrate it into the plugin itself. It's a great thing to have.

Keep up the great work!
Creator of "Let Bions be bygones"
https://linktr.ee/bohemianpulp
User avatar
Tony Li
Posts: 22037
Joined: Thu Jul 18, 2013 1:27 pm

Re: Combine two Dialogue Entries into a single sentence

Post by Tony Li »

Thanks! I'll write this up as a "How To" post here.
Post Reply