HELP! Get the name of the choice made not the index.

Hi all!
im making some show choices by script call. Everything works except I dont wan to get the index of the choice but the name:
I found this code on a post:

Code:
choices = []; params = [];
$gameMessage.setChoices(choices, 0)
choices.push("Yes");
choices.push("No");
params.push()


$gameMessage.setChoiceCallback(function(responseIndex) {
if (responseIndex === 0) {
// Player chose "Yes"
$gameScreen.startFlash([250, 250, 250, 100], 60);
} else {
$gameScreen.startFlash([0, 0, 250, 100], 60);
}
});

So I know that responseIndex will get me the index of the choice made, but what if want to handle my if else statements by name? Like :
Code:
if (NAME == "Yes") {
bla bla
}
I need the name of the choice since I'm hiding and showing choices, so index is no bueno.

Thank you!!
You just need to reference the choices array you've set up. Your script call actually implicitly defines choices on the global scope, though, because you haven't used a local declarator like var. That may cause problems if you're doing this back-to-back, since you don't tell the event to pause until a choice is made.

Instead, I suggest something like this:
JavaScript:
var choices = ["Yes", "No"];
$gameMessage.setChoices(choices, 0, -1);  // default 0, no cancel
$gameMessage.setChoiceBackground(0);  // Window
$gameMessage.setChoicePositionType(0);  // Left
$gameMessage.setChoiceCallback(n => {
  $gameVariables.setValue(1, choices[n]);
});
this.setWaitMode('message');  // Wait for choice
As-is, this just stores the name of the selected choice in game variable 1, to be checked later. Alternatively you can do the check within the callback function, like in your original example.

(This example was adapted from the Show Choices entry on the MV / MZ Script Call List.)
Thanks @caethyril . Even thou i understand (somewhat) JavaScript code, i have troubles with arrow functions, and im not allowed to use them in Maker MV. Would you help me with the syntaxis on how I should run it?

Thank you =)
Ah, sorry, I usually try to remember to avoid arrow functions for MV. 😴

You can simply replace this line:
JavaScript:
$gameMessage.setChoiceCallback(n => {
...with this:
JavaScript:
$gameMessage.setChoiceCallback(function(n) {
However, the latest version of RPG Maker MV supports arrow functions, and has probably fixed some bugs and performance concerns, so you may want to consider updating your editor. 👋
Got it!! Thank you=), I got it to work now =).

Im unable to change versions, got stuck at 1.51 since I have too many plug ins that will break with newer versions, have thousands of hours already and since i cannot code, it would take a lot of money or time to redo some plug ins.

Any way! Thank you again =)
You're welcome! Happy RPG Making~ 😂

Original thread: https://forums.rpgmakerweb.com/threads/help-get-the-name-of-the-choice-made-not-the-index.162433/