Best way to add inline lua markup tag?
Posted: Sun Feb 02, 2020 4:45 am
Hey!
I have a bit of in-line Lua that I use to check gender and return the appropriate pronoun or whatever word ("Hey young man/woman").
I'd really prefer to have that node's text look something like this:
I looked at registering functions and that doesn't seem to be where I want to go to achieve this so I'd appreciate any help because this will really help out writing dialogue and for localization as well.
EDIT:
Nevermind. Looking at FormattedText.cs, it's looking like adding my own tag would be messy so I'm just rolling it out into a function that ends up being [lua(g("male", "female"))], which is close enough.
Here's the code in case anyone else wants to do the same thing:
Then in a node, just do this wherever you want to have gendered dialogue:
EDIT2:
Better version in my reply below.
I have a bit of in-line Lua that I use to check gender and return the appropriate pronoun or whatever word ("Hey young man/woman").
Code: Select all
You are a [lua(return Variable["Gender"] == "Male" and "male" or "female" )].
Code: Select all
You are a [g("male", "female")].
EDIT:
Nevermind. Looking at FormattedText.cs, it's looking like adding my own tag would be messy so I'm just rolling it out into a function that ends up being [lua(g("male", "female"))], which is close enough.
Here's the code in case anyone else wants to do the same thing:
Code: Select all
public class LUAGenderCheck : MonoBehaviour
{
public string playerGenderVariable = "Male";
private void OnEnable()
{
Lua.RegisterFunction("g", this, SymbolExtensions.GetMethodInfo(() => GetPlayerGender(String.Empty, String.Empty)));
}
public string GetPlayerGender(string male, string female)
{
return playerGenderVariable == "Male" ? male : female;
}
}
Code: Select all
You are a [lua(g("male", "female"))].
Better version in my reply below.