Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Switching pronouns around

Discussion in 'Scripting' started by Daoxin7, Oct 20, 2017.

  1. Daoxin7

    Daoxin7

    Joined:
    Oct 20, 2017
    Posts:
    5
    So working on a game and if the user picks a gender at the start of the game, I want to reflect that respective gender in the dialogue without resorting to copying all the same text and just change the pronouns manually for it. Is there a way to call out certain pronouns and input them to the dialogue when needed after the choice of a gender?

    I was thinking using bool on this and make male and female to be false but not sure how it will work entirely if I do that.
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    For sure, you could do something like this...

    Let's say you have a few options: his/her , his/hers, him/her, he/she whatever :)

    You could give a special "Symbol" (just a special string of text) to indicate which you'd like to use.

    I would use an int for the gender, personally. This would allow you to index into an array of options. You could set them up maybe like so:
    Code (csharp):
    1.  
    2. int gender = 0; // using 0 or 1  (or 0, 1, 2.. if you might ever have 'unset')
    3. string [] heshe = { "he", "she" };
    4.  
    Later, your string to modify might look like:
    Code (csharp):
    1.  
    2. string phrase = "_HESHE_ was really happy";
    3. // when using the phrase:
    4. string newPhrase = phrase.Replace("_HESHE_", heshe[gender]);
    5.  
     
    Daoxin7 and MaxGuernseyIII like this.
  3. MaxGuernseyIII

    MaxGuernseyIII

    Joined:
    Aug 23, 2015
    Posts:
    315
    You can also have an object for gender with all the relevant properties instead of an index into a number of lookup tables. No matter how you factor it, though, I can't imagine doing anything other than the same basic idea expressed by @methos5k, above.
     
    Daoxin7 likes this.
  4. Daoxin7

    Daoxin7

    Joined:
    Oct 20, 2017
    Posts:
    5
    Thanks you guys will try it out then. :)
     
  5. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    No problem :)