How to vary word according to a switch?

In my game, I have multiple treatment options besides man/woman. As an alternative to creating multiple "If switch X is on" before each message, I'd like to choose the one specific word (maybe added to a dictionary of something like that) according to the player's option.

In portuguese, the words are way too more oftenly gendered than in english, so I really need that.

For example: the word for a romantic companion would change according to what the player chose in the beginning of the game, so I'd like the word "boyfriend/girlfriend/etc" to change according to that, without having to manually add "if switch X is on" every time I want to "gender" a word.

Is there a plugin for adding words to a custom dictionary, that makes it change according to what switch is on/off?

For example:

I type: "This is my boyfriend" in the chat box, but if the character is a woman (pre-established with a switch), it automatically shows "This is my girlfriend" in-game.

If my request is not clear, I can try to explain it better, thanks.

I've moved this thread to MV Support. Thank you.


I'm not at my computer so I can't double-check, but I'm pretty sure you can set a word like 'boyfriend' or 'girlfriend' in a variable when the character choice is made and have that variable called during the message to make the right word show up.
you could potentially make a single table with all the gendered words, and use a function to retrieve them based on that switch.
for instance, at the point of retrieving that word, you'd call for getTerm("romantic_partner"), and *it* would return either the male OR female form based on the state of the switch, which *it* itself will check for.
one check, one switch, one call, multiple results, all depending on the key search term.
basically, a discount localization database.
I don't know portugese, but I assume, as most latin based languages, nouns and adjectives are gendered, which can make it pretty hard if you rely on a "dictionnary" solution (lots of words to add potentially). Whereas using conditional branches allows you to clearely write 2 distinct texts (and potentially more customisation).
It's your call, but you might want to take a moment to think about what way is easier to implement in your game.
Spoiler: Plugin info taken for forum post
If you only need small changes, then I wouldn't use conditional branches, because you'll have to write the same text twice every time you need to use male/female pronouns.

A plugin would be much better suited.
So I wrote one for you:

Code:
//=============================================================================
// GenderSpecificMessages
//=============================================================================
/*:
 * @plugindesc Provides a method to easily make changes to messages depending on the player's gender.
 * @author Nolonar
 *
 * @param Gender Switch ID
 * @desc The ID of the Switch that defines the player's gender.
 * @default 1
 * @type number
 *
 *
 * @help
 * Adds the following control character:
 * \x[male|female]
 *
 * Example
 *     "Hello, young \x[man|lady]! How are you today?"
 *
 * If switch is off -> Hello, young man! How are you today?
 * If switch is on -> Hello, young lady! How are you today?
 */
(function() {
//=============================================================================
// Settings
//=============================================================================
    var Parameters = PluginManager.parameters('GenderSpecificMessages');
    var Param = {
        GenderSwitchId: Number(Parameters['Gender Switch ID'])
    }
    var IsFemale = function() {
        return $gameSwitches.value(Param.GenderSwitchId);
    }
//=============================================================================
// Window_Base
//=============================================================================
    var _Window_Base_convertEscapeCharacters = Window_Base.prototype.convertEscapeCharacters;
    Window_Base.prototype.convertEscapeCharacters = function(text) {
        text = _Window_Base_convertEscapeCharacters.call(this, text);
        text = text.replace(/\x1bx\[(.*?)\|(.*?)\]/gi, function() {
            return IsFemale() ? arguments[2] : arguments[1];
        });
        return text;
    };
})();

How to install:
In your project's folder, there's a "js" folder. Inside, there's a "Plugins" folder with a couple of .js files.
Make a copy of one of the .js files. To do so, select a file (for instance "AltMenuScreen.js"), press Ctrl + C, then Ctrl + V, and the copy will appear (in this case "AltMenuScreen - copy.js").
Rename the copy into "GenderSpecificMessages.js".
Open the file in Notepad (or Notepad++). To do so, right-click on the file and click on "Edit" instead of "Open".
Replace the content of the file with the plugin code from above.

Open RMMV.
Open the Plugin Manager (click on the jigsaw icon, to the right of the Database).
There should already be 2 plugins. Click below the last plugin to select an empty row. Double-click the empty row.
Under "Name" select our plugin ("GenderSpecificMessages"), then click OK.

How to use:
1. You need a Switch that defines if the player is male or female (ON means female, OFF means male). If you want it to be the other way around (ON for male, OFF for female), then just modify the plugin, like this:
Code:
            return IsFemale() ? arguments[1] : arguments[2];
Just find the line that looks very similar and replace it with this new one.
By default, the gender Switch is Switch #0001. If you want to use a different switch, just change the plugin's setting. To do so, open the Plugin Manager, double-click on our plugin ("GenderSpecificMessages"), then double-click on "Gender Switch ID" on the right, then input another number.

2. When you write a message, you can insert "\x[male|female]" so RMMV will automatically select the right one.
For example:
Hello, young \x[boy|girl], how are you today?

Will change to
Hello, young boy, how are you today?
or
Hello, young girl, how are you today?
depending on whether the Switch is ON or OFF.


Important note:
If you need vastly different messages, like:
Male: "Who are you, man? Why are you looking at me like that?"
Female: "Hello, beautiful! Would you like to have a chat over tea?"

then you should use a Conditional Branch instead. The plugin is only for small differences.


Ah, before I forget...
Terms of use for the plugin:
Feel free to use it as you like for any RPG Maker project, commercial or non-commercial.
No need to mention me in the credits if you don't want to.
Feel free to modify the plugin as necessary.
You may redistribute the plugin if you like, as long as you don't change the "@author Nolonar" part or claim the plugin for your own.
You're not allowed to sell the plugin by itself or as part of a resource pack, but it's OK to sell RPG Maker games that use the plugin.

I think this plugin by @Nolonar from this thread might work for you. It's really easy and lets you choose a variety of words for gender based on what you put in a text box. So for example, you could have [girl|boy] or [him|her], etc, without needing a variable or conditional for each different word.

I have been using it and it's been very useful so far!
Eventcommand Control Variables 1 to Script: "Attack Helicopter"

Eventcommand Textbox: This is my \V[1]
This would look ingame like this: This is my Attack Helicopter.
Dont forget the " " , you need them to make Letters into Word Strings for the Engine.
Thanks a lot, folks. You gave me some ideas! I'll try the plugin and the other useful strategies
I've taken a look at the thread and it looks like there's only 2 options, but it may help a lot. I'll message the author and keep looking for more ideas. Thanks!
Please don't double post (post underneath yourself), just edit your previous post if you've got something to add.

I will second Bex's solution, to simply name a variable. So each gendered word will be replaced by a variable, which you set at the beginning when the player has picked their gender.

So instead of writing "He picked up his bag." you would write "\v[6]" picked up \v[7]" bag." With Variable 6 being either He/She/They etc. and variable 7 being His/Hers/Theirs. Of course, you can do whatever you want with these variables.

To set a variable to a word, use the Script command, and type the word in between two quotes. Like so:
YmQqa2q.png


This way you don't need to create a conditional branch each time you have the word come up (you only do this once, at the beginning).
Please don't double post (post underneath yourself), just edit your previous post if you've got something to add.

I will second Bex's solution, to simply name a variable. So each gendered word will be replaced by a variable, which you set at the beginning when the player has picked their gender.

So instead of writing "He picked up his bag." you would write "\v[6]" picked up \v[7]" bag." With Variable 6 being either He/She/They etc. and variable 7 being His/Hers/Theirs. Of course, you can do whatever you want with these variables.

To set a variable to a word, use the Script command, and type the word in between two quotes. Like so:
YmQqa2q.png


This way you don't need to create a conditional branch each time you have the word come up (you only do this once, at the beginning).

That will definitely work! Thank you very much

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-vary-word-according-to-a-switch.104295/