Page 1 of 1

How to show text from Text Table in dialogue node?

Posted: Mon Aug 09, 2021 6:06 pm
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?

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

Posted: Mon Aug 09, 2021 8:13 pm
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.

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

Posted: Tue Aug 10, 2021 4:20 pm
by vcesauron
Will test it soon, but registering a Lua function sounds good (I should have thought of that...)
Thanks, Tony!