How to show text from Text Table in dialogue node?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
vcesauron
Posts: 19
Joined: Tue Oct 06, 2020 11:22 am

How to show text from Text Table in dialogue node?

Post by vcesauron »

Hello. What should I do if I want a Node to show a Text Table entry?

I was thinking of using the markup tag [lua(GetLocalizedText(...))], but according to the docs:
The function GetLocalizedText() retrieves localized versions of fields in the Actor, Item, Quest, or Location tables.
(...)

GetLocalizedText( tableName, elementName, fieldName )
where:

tableName is "Actor", "Item", "Quest", or "Location",
(...)
There's no tableName for the actual Text Table.
How can I do this?
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to show text from Text Table in dialogue node?

Post by Tony Li »

Hi,

You could write a C# function GetTextField(string fieldName):

Code: Select all

public void GetTextField(string fieldName) { return DialogueManager.GetLocalizedText(fieldName); }
Then register it with Lua and use the markup tag [lua(GetTextField("your-field"))].

Alternatively, you could add a script with an OnConversationLine method to the Dialogue Manager, such as:

Code: Select all

public void OnConversationLine(Subtitle subtitle)
{
    // Replace all strings of the format {{field-name}} with the localized Text Table value of field-name:
    subtitle.formattedText.text = Regex.Replace(subtitle.formattedText.text, @"{{.+?(?=}})}}", m => DialogueManager.GetLocalizedText(m.Value.Substring(2, m.Value.Length - 4)));
}
That's a bit of a convoluted regex, but the idea is that it replaces any substrings of the form {{field-name}} with the localized value of field-name in the text table.
User avatar
vcesauron
Posts: 19
Joined: Tue Oct 06, 2020 11:22 am

Re: How to show text from Text Table in dialogue node?

Post by vcesauron »

Will test it soon, but registering a Lua function sounds good (I should have thought of that...)
Thanks, Tony!
Post Reply