Announcements, support questions, and discussion for the Dialogue System.
DragoonHP
Posts: 62 Joined: Tue Jan 15, 2019 8:17 am
Post
by DragoonHP » Tue Apr 09, 2019 7:47 am
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.
Tony Li
Posts: 22104 Joined: Thu Jul 18, 2013 1:27 pm
Post
by Tony Li » Tue Apr 09, 2019 9:21 am
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"))]?"
DragoonHP
Posts: 62 Joined: Tue Jan 15, 2019 8:17 am
Post
by DragoonHP » Tue Apr 09, 2019 11:13 am
Okay.
I think I will use the subtitle method as its very flexible compared to the lua translate.
Thanks for the quick reply