[HOWTO] How To: Handle Player Gender In Dialogue Text

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Tony Li
Posts: 22143
Joined: Thu Jul 18, 2013 1:27 pm

[HOWTO] How To: Handle Player Gender In Dialogue Text

Post by Tony Li »

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:
  • (m): "Je suis danseur."
  • (f): "Je suis danseuse."
One way to handle this is to adopt a special format to specify gendered options, such as:

"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];
}
Post Reply