Create a list with eventing

Hello, how can I create a list of selectable choices that when certain switch is on, the name of the corresponding choice changes it's name?

It's probably similar to YEP common event menu, but without plugin. Just wondering if this is doable without plugin.
Is it just the one option you need to do this or will there be a number of them?
Here's the code to create a choice window:
JavaScript:
choices = []; //array variable for the choices
$gameMessage.setChoices(choices, -1, -1);
$gameMessage.setChoicePositionType(1);
$gameMessage.setChoiceCallback(function(n){
  //stuff to do, choices[n] returning the text of the choice picked
}.bind(this));
this.setWaitMode('message');
Now to add choice options based on switches being on, add this after choices = []:
JavaScript:
if($gameSwitches.value(X)) choices.push("choice text");
There could be a way to optimize this so it fits in a script call command, it all depends on what you're trying to do precisely.
@Trihan
Many, hence it's a list 🙂
For example, if it's a switch array ordered the same as actors, you could do:
JavaScript:
for(i=1; i <= 10; i++) {
    if($gameSwitches.value(i)) choices.push($gameActors.actor(i).name());
}
Which would add an actor's name to the list only if their matching switch (whose ID is the same as the actor) is ON.
If you want to keep the purpose of your list a secret, I'll let you figure out how you'll make it all fit into a script call command.
Hello, how can I create a list of selectable choices that when certain switch is on, the name of the corresponding choice changes it's name?

It's probably similar to YEP common event menu, but without plugin. Just wondering if this is doable without plugin.
I would assume to achieve something like this it would be a rather complex series of nested If-Then Conditional Branches blended with Choice Lists... so for example, say your choices are Blue Red and Green; but with Switch A is on, the choices become Blue Red Orange:

I believe you would achieve such a thing, through eventing alone with something like this:
Conditional Branch - Switch A is ON, create Else branch

If ON, Show Choices: Blue Red Orange - Choice details inside each.
Else, Show Choices: Blue Red Green - Choice Details.

You would manually just swap out the 'names' of the choices when you create the branches, depending on whether the switch is on or not. If you are having multiple switches affect them at the same time - say a Switch B to replace Red with Purple... then you would just have

Conditional Branch - Switch A On
If ON,
Conditional Branch - Switch B On
If ON, Choices -Blue Purple Orange
Else, Choices - Blue Red Orange
Else, Choices Blue Red Green.

If that makes any sense at all. Lol. It is hard to visually explain what is going on without flooding the post with screen shots after screen shot from in-game. But I would be happy to recreate these lists in-engine if you would like.
To literally just change the text of the choice, you can do this:
  • Store a string (i.e. text) in a game variable, e.g.
    Control Variables -> Script: "this is an example"​

  • Then use the \V[x] text code in the choice text, e.g. \V[123]
This approach requires one game variable per choice.
Spoiler: Event example
Code:
◆If:cakeEaten is ON
  ◆Control Variables:#0006 Text = "The cake is a lie"
  ◆
:Else
  ◆Control Variables:#0006 Text = "I come bearing cake!"
  ◆
:End
◆Text:None, Window, Bottom
:    :Halt! \|What's the password?
◆Show Choices:\V[6], [Walk away] (Window, Right, #1, #2)
:When \V[6] 
  ◆Text:None, Window, Bottom
  :    :Wrong answer!
  ◆
:When [Walk away] 
  ◆
:End
If you want to change what happens when the choice is selected, you'll need to either:
  • Add 1 or more branches within that choice (e.g. is switch on), or
  • Use a different approach, e.g. a plugin that lets you conditionally hide choices.
if you have many changing options, your best bet might be to use tsukihime's plugins, especially Choice Options (if I remember the name correctly)
Alternate option: use hidden items to give the player options based on conditions.

Create one for every option you want, name it accordingly, and add it to the player's inventory if the condition for that option to show up is fulfilled. Then, set a temporary variable to 0 and make the player pick a hidden item. Select the same category as the hidden items you made, and store the choice into the temporary variable.

After the choice, remove all the possible hidden items. If the variable is still 0, that means the player cancelled. Otherwise, the variable has become the database ID of the item that was picked. Use conditions to handle them the way you want.

I've had this system in a project, the way I handled it afterwards is that I added the choice item to the inventory so the player now has 2, then I removed 1 of each choice item. After that, I had an autorun event whose condition was that choice item, which covered everything that happened if the player picked that item. Don't forget to remove it at some point during the event so it doesn't loop.
For example, if it's a switch array ordered the same as actors, you could do:
JavaScript:
for(i=1; i <= 10; i++) {
    if($gameSwitches.value(i)) choices.push($gameActors.actor(i).name());
}
Which would add an actor's name to the list only if their matching switch (whose ID is the same as the actor) is ON.
If you want to keep the purpose of your list a secret, I'll let you figure out how you'll make it all fit into a script call command.

The purpose of my list is the same as yanfly common event menu, item book or achievement. It displays a list of ???????? choices. When you turn on certain switch, the ?????? become a selectable choice. Then players can select them to view the detail information.

It is very much like item book, except it isn't "getting an item" that triggers choice name change.

To literally just change the text of the choice, you can do this:
  • Store a string (i.e. text) in a game variable, e.g.
    Control Variables -> Script: "this is an example"​
  • Then use the \V[x] text code in the choice text, e.g. \V[123]
This approach requires one game variable per choice.
Spoiler: Event example
Code:
◆If:cakeEaten is ON[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]  ◆Control Variables:#0006 Text = "The cake is a lie"[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]  ◆[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]:Else[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]  ◆Control Variables:#0006 Text = "I come bearing cake!"[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]  ◆[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]:End[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]◆Text:None, Window, Bottom[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]:    :Halt! \|What's the password?[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]◆Show Choices:\V[6], [Walk away] (Window, Right, #1, #2)[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]:When \V[6][/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]  ◆Text:None, Window, Bottom[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]  :    :Wrong answer![/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]  ◆[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]:When [Walk away][/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]  ◆[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]:End
If you want to change what happens when the choice is selected, you'll need to either:
  • Add 1 or more branches within that choice (e.g. is switch on), or
  • Use a different approach, e.g. a plugin that lets you conditionally hide choices.

@caethyril

Where can I find the option to change the text for variables?

Edit: @CHKNRAVE I tried your method. I don't know if I'm doing this correctly. I turned on switch 2 and set choices = [2]. Then the game says text.replace is not a function.
Where can I find the option to change the text for variables?
  • Choose the Control Variables command.
  • You should see a window with 3 groups of options:
    • Under Variable, select the variable you want to store the text in;
    • Under Operation, choose Set (default);
    • Under Operand, choose Script and type your text, in "quotes", in the box next to that.
      E.g. "this is an example".
The "quotes" are important: they mark it as text rather than a variable or something.

To add text to existing text, use the Add operator instead, e.g. this NPC says cheesecake:
Code:
◆Control Variables:#0006 Text = "cheese"
◆Control Variables:#0006 Text += "cake"
◆Text:None, Window, Bottom
:    :\V[6]

Alternatively, like Andar suggested, you may find the choice plugins by Tsukihime/HimeWorks helpful, e.g.

If you're still confused about variables in RPG Maker then I strongly recommend you look up tutorials on how to use them. Even if you use a different approach for this problem, variables are very useful for game development.
Edit: @CHKNRAVE I tried your method. I don't know if I'm doing this correctly. I turned on switch 2 and set choices = [2]. Then the game says text.replace is not a function.
That's not how it works. You need to create an array of strings based on the switches that are activated.
JavaScript:
choices = [] //leave as it is
if($gameSwitches.value(2)) choices.push("option for switch 2");

Original thread: https://forums.rpgmakerweb.com/threads/create-a-list-with-eventing.134787/