Page 1 of 1

Replace subtitle content on the fly

Posted: Tue Apr 09, 2019 7:47 am
by DragoonHP
Is there a way to swap words and phrases on the fly? In game, some characters can only be understood if the player has learnt their language so I was wondering if there is a quick and easy way of replacing text?

Is using

Code: Select all

OnConversationLine(Subtitle subtitle)
and then changing subtitle.formattedText the way to go?
Thanks.

Re: Replace subtitle content on the fly

Posted: Tue Apr 09, 2019 9:21 am
by Tony Li
Yes, that's the best way if you're replacing the entire text.

If you're only replacing words or phrases, another way is to write a C# function and register it with Lua, such as:

Code: Select all

static string Translate(string word) { // (example)
    if (playerKnowsLanguage) return word;
    else if (word == "rock") return "blaboo"
    else if (word == "water") return "flizzit";
    else return "???";
}

void Awake() {
    Lua.RegisterFunction("Translate", this, SymbolExtensions.GetMethodInfo(() => Translate(string.Empty)));
}
Then in your Dialogue Text, use [lua(Translate("word"))], such as:
  • Dialogue Text: "Would you like some [lua(Translate("water"))]?"

Re: Replace subtitle content on the fly

Posted: Tue Apr 09, 2019 11:13 am
by DragoonHP
Okay.

I think I will use the subtitle method as its very flexible compared to the lua translate.
Thanks for the quick reply