Custom Markup Tags?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
DarkProphet
Posts: 15
Joined: Thu Dec 16, 2021 2:09 pm

Custom Markup Tags?

Post by DarkProphet »

Is it possible to create custom Lua markup tags like [auto] and [f]?
Essentially I'm currently using Rich Text Tags to insert sprites into my Response buttons, such as <sprite name="prayer">.
It's working fine, but I would love a less verbose solution, something like [prayer].

If not possible, is there another solution that would suit the following needs:
- Need custom response buttons or button icons that can easily be assigned to dialogue response entries.
- If custom buttons, need to be able to use same button look for multiple possible entries (so I believe static [position] references would not work)
- Ideally, if the response entries could also have a custom color assigned in the Conversation node editor, that would make troubleshooting at a glance much easier!
User avatar
Tony Li
Posts: 22093
Joined: Thu Jul 18, 2013 1:27 pm

Re: Custom Markup Tags?

Post by Tony Li »

Hi,

You can add a script with OnConversationLine and OnConversationResponseMenu special methods to the Dialogue Manager. Example:

Code: Select all

void OnConversationLine(Subtitle subtitle)
{
    subtitle.formattedText.text = ReplaceSpecialMarkupTags(subtitle.formattedText.text);
}
void OnConversationResponseMenu(Response[] responses)
{
    foreach (var response in responses)
    {
        response.formattedText.text = ReplaceSpecialMarkupTags(response.formattedText.text);
    }
}
string ReplaceSpecialMarkupTags(string text)
{
    return text.Replace("[prayer]", "<sprite name=\"prayer\">");
}
DarkProphet
Posts: 15
Joined: Thu Dec 16, 2021 2:09 pm

Re: Custom Markup Tags?

Post by DarkProphet »

Nice one.
I implemented this, however, the text.Replace function seems to not be working.
The events fire (Debug.Log outputs the text from ReplaceSpecialMarkupTags(), but Replace never does any actual replacing.
I've tried it with multiple different words, even single letters. Replace() seems to just return the initial string, unchanged. :?:
User avatar
Tony Li
Posts: 22093
Joined: Thu Jul 18, 2013 1:27 pm

Re: Custom Markup Tags?

Post by Tony Li »

Hi,

Here's an example scene:

DS_TestReplaceTags_2024-10-25.unitypackage

It replaces "[friend]" with the string "good old buddy old pal".
DarkProphet
Posts: 15
Joined: Thu Dec 16, 2021 2:09 pm

Re: Custom Markup Tags?

Post by DarkProphet »

Thanks,
I figured out what was wrong.
I had multiple lines of replace and forgot to assign the text back to itself like this:

Code: Select all

text = text.Replace("[key]", "replaced key");
text = text.Replace("[other]", "replaced other");
return text;
I was just going:

Code: Select all

text.Replace("[code]", "replaced text")
return text;
which just returned the original text with no replacement.
User avatar
Tony Li
Posts: 22093
Joined: Thu Jul 18, 2013 1:27 pm

Re: Custom Markup Tags?

Post by Tony Li »

I can vouch from personal experience that you're not the first to do that. ;)
Post Reply