[HOWTO] How To: Handle Player Gender In Dialogue Text
Posted: Tue Nov 22, 2022 11:06 pm
This article describes one way to handle player character (PC) gender in dialogue text.
If the player can choose the PC's gender between male and female, you may need to modify the text to handle gendered pronouns or words in gendered languages.
Take for example the sentence: "I am a dancer." In French, this is:
"Je suis {{danseur/danseuse}}."
Then add an OnConversationLine method to a custom script on the Dialogue Manager GameObject. In that method, replace the "{{danseur/danseuse}}" with one version or the other based on the PC's gender. Example:
You could also do this with a Lua function, which would result in a simpler C# method but more verbose dialogue text:
"Je suis [lua(Gender("danseur/danseuse"))]."
where the C# method registered with Lua might look something like:
If the player can choose the PC's gender between male and female, you may need to modify the text to handle gendered pronouns or words in gendered languages.
Take for example the sentence: "I am a dancer." In French, this is:
- (m): "Je suis danseur."
- (f): "Je suis danseuse."
"Je suis {{danseur/danseuse}}."
Then add an OnConversationLine method to a custom script on the Dialogue Manager GameObject. In that method, replace the "{{danseur/danseuse}}" with one version or the other based on the PC's gender. Example:
Code: Select all
void OnConversationLine(Subtitle subtitle)
{
Regex regex = new Regex(@"{{[^}]*}}");
subtitle.formattedText.text = regex.Replace(subtitle.formattedText.text, delegate (Match match)
{
var strings = match.Value.Substring(2, match.Value.Length - 4).Split('/');
return isPlayerMale ? strings[0] : strings[1];
});
}
You could also do this with a Lua function, which would result in a simpler C# method but more verbose dialogue text:
"Je suis [lua(Gender("danseur/danseuse"))]."
where the C# method registered with Lua might look something like:
Code: Select all
public string Gender(string s)
{
var strings = s.Split('/');
return isPlayerMale ? strings[0] : strings[1];
}