Different redaction for the same dialgue node.

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
perezbalen
Posts: 40
Joined: Mon May 24, 2021 7:22 pm

Different redaction for the same dialgue node.

Post by perezbalen »

I want to use a dialogue node several times. But have the same node say something different every time (mostly). For instance, you say hello to the shopkeeper. The first time he answers. “Welcome” the second time, “welcome back.” The third time “have I seen you before?”
And I want to do this a lot.
Following the barks and quest video tutorial, I can get this behavior. But this makes the dialogue tree super complex, extremely fast.
So, my question is, has someone found a better way to do this? I was thinking having each dialogue node look at an array or lists of responses and having a function to go one by one each time, or maybe choose randomly.
Thanks.
User avatar
Tony Li
Posts: 22163
Joined: Thu Jul 18, 2013 1:27 pm

Re: Different redaction for the same dialgue node.

Post by Tony Li »

Hi,

For a non-scripting option, you can link the <START> node to several dialogue nodes, each one with a different line of text ("Welcome", "Welcome back", "Hi there", etc.). You can put Conditions on them so that, for example, "Welcome back" only appears if the player has spoken to the NPC before.

In addition, you can use the RandomElement() Lua function if you want to include random text:
  • Dialogue Text: "[lua(RandomElement( "Welcome|Welcome back|Hi there" ))]"
Or:
  • Dialogue Text: "[lua(RandomElement( "Welcome|Welcome back|Hi there" ))], [lua(RandomElement("friend|buddy"))]"
I prefer to use the techniques above because they keep the text options visible and in one place. However, if you want to do it in a script, you can use an OnConversationLine method to preprocess the text before it's displayed. For example, say you set a convention that the substring "{greeting}" should be replaced by a random greeting. Then your method might look like:

Code: Select all

public string[] greetings = new string[] { "Welcome", "Welcome back", "Hi there" };
 
 void OnConversationLine(Subtitle subtitle) // Make sure script is on Dialogue Manager or conversation participant.
 {
     if (subtitle.formattedText.text.Contains("{greeting}"))
     {
         string randomGreeting = greetings[Random.Range(0, greetings.Length)];
         subtitle.formattedText.text = subtitle.formattedText.text.Replace("{greeting}", randomGreeting);
     }
 }
perezbalen
Posts: 40
Joined: Mon May 24, 2021 7:22 pm

Re: Different redaction for the same dialgue node.

Post by perezbalen »

Thanks. Gonna try it.
Post Reply