Need some help for setting up Random Choices in dialogue

I could use a hand... I've done it in the past, but I honestly don't remember how, and I can't find the project where I've done it...
So, I want to set up a dialogue that pops up when reaching certain areas (no problem).
This dialogue will present you with 3 options, option 1 and 2 will be Fix every time (again no problem).
Option 3 however, I want to give a selection of 3 random choices out of 20.

So every time you encounter this dialogue, you can choose:
1. Fix option
2. Fix option
3. Random option:
-Random Option 1/20
-Random Option 2/20
-Random Option 3/20

It's probably not as hard as I'm making it

Thanks for any hints nudges and help
You'd either make 20 versions of the Show Choices and put them inside Conditional Branches based on the value of a random value;

or use a Conditional Choices plugin to change what the third one says based on said random value. I think one of the HimeWorks will do that.
You'd either make 20 versions of the Show Choices and put them inside Conditional Branches based on the value of a random value;

or use a Conditional Choices plugin to change what the third one says based on said random value. I think one of the HimeWorks will do that.
Thanks ATT ill give that a look
I'm assuming you're trying to achieve 5 choices total (nested or otherwise), e.g.
  • A
  • B
  • C1
  • C2
  • C3
Where C1, C2, and C3 are all different choices randomly selected from the same pool of 20.


For random selection you can roll 3 random numbers (Control Variables -> Set -> Random), using offsets (Control Variables -> Add -> Constant) to ensure they are all different:
  • C1: random 1~20.
  • C2: random 1~19, then +1 if value is ≥ C1.
  • C3: random 1~18, then +1 if value is ≥ C1, then +1 again if value is ≥ C2.


Note that if you have 20 possible choices and you want to pick 3 of those to display, that's a bit more than just 20 combinations. 20 choose 3 is 20! / (3! x 17!) = (20 x 19 x 18) / 6 = 1140 different combinations. I would not recommend having that many branches. 😅
Spoiler: ideas
  1. Like Turan suggests, the easiest approach is probably to find plugin(s) that can conditionally hide/show choices, as well as support more than 6 potential choices per command.

  2. Otherwise you could consider Select Item, e.g. with type Hidden Item A or B (since those don't show in the menu). Maybe not what you want, display-wise. No scripting required, though:
    • Make 1 item per applicable choice;
    • Get 3 random choice numbers;
    • Add the corresponding 3 choice items (20 x Conditional Branch -> Change Item);
    • Select Item for the choice item type;
    • Remove all 20 choice items (20 x Change Item);
    • Respond based on value of variable from Select Item (20 x Conditional Branch).

  3. Alternatively: variables can store text, and Show Choices supports the \V[x] text code, so you can implement "conditional choice text" without a plugin. This would let you roll the random choices, then do a 3-choice Show Choices command and respond appropriately. I would consider something like this in a Script command to get the choice texts into variables:
    JavaScript:
    const choices = ["Choice A", "Choice B", "Choice C", "Choice D"]; // etc
    $gameVariables.setValue(101, choices[$gameVariables.value(1) - 1]);
    $gameVariables.setValue(102, choices[$gameVariables.value(2) - 1]);
    $gameVariables.setValue(103, choices[$gameVariables.value(3) - 1]);
    You'd need to edit the first line to cover all 20 possible choices. This assumes the random values are stored in variables 1~3, and the text is stored in variables 101~103 respectively. Then check player response as with Select Item.

  4. Or you could use the script call version of Show Choices. I don't recall what that is off the top of my head, but it's on the Script Call List:
    Like with the previous idea, you'd still need some kind of process to determine the appropriate choice text.
I'm assuming you're trying to achieve 5 choices total (nested or otherwise), e.g.
  • A
  • B
  • C1
  • C2
  • C3
Where C1, C2, and C3 are all different choices randomly selected from the same pool of 20.


For random selection you can roll 3 random numbers (Control Variables -> Set -> Random), using offsets (Control Variables -> Add -> Constant) to ensure they are all different:
  • C1: random 1~20.
  • C2: random 1~19, then +1 if value is ≥ C1.
  • C3: random 1~18, then +1 if value is ≥ C1, then +1 again if value is ≥ C2.


Note that if you have 20 possible choices and you want to pick 3 of those to display, that's a bit more than just 20 combinations. 20 choose 3 is 20! / (3! x 17!) = (20 x 19 x 18) / 6 = 1140 different combinations. I would not recommend having that many branches. 😅
Spoiler: ideas
  1. Like Turan suggests, the easiest approach is probably to find plugin(s) that can conditionally hide/show choices, as well as support more than 6 potential choices per command.

  2. Otherwise you could consider Select Item, e.g. with type Hidden Item A or B (since those don't show in the menu). Maybe not what you want, display-wise. No scripting required, though:
    • Make 1 item per applicable choice;
    • Get 3 random choice numbers;
    • Add the corresponding 3 choice items (20 x Conditional Branch -> Change Item);
    • Select Item for the choice item type;
    • Remove all 20 choice items (20 x Change Item);
    • Respond based on value of variable from Select Item (20 x Conditional Branch).

  3. Alternatively: variables can store text, and Show Choices supports the \V[x] text code, so you can implement "conditional choice text" without a plugin. This would let you roll the random choices, then do a 3-choice Show Choices command and respond appropriately. I would consider something like this in a Script command to get the choice texts into variables:
    JavaScript:
    const choices = ["Choice A", "Choice B", "Choice C", "Choice D"]; // etc
    $gameVariables.setValue(101, choices[$gameVariables.value(1) - 1]);
    $gameVariables.setValue(102, choices[$gameVariables.value(2) - 1]);
    $gameVariables.setValue(103, choices[$gameVariables.value(3) - 1]);
    You'd need to edit the first line to cover all 20 possible choices. This assumes the random values are stored in variables 1~3, and the text is stored in variables 101~103 respectively. Then check player response as with Select Item.

  4. Or you could use the script call version of Show Choices. I don't recall what that is off the top of my head, but it's on the Script Call List:
    Like with the previous idea, you'd still need some kind of process to determine the appropriate choice text.
I looked in to eventing this, but quickly realized that it's not very realistic and not at all a quick way of doing it, especially because 20 was only a random number I chose (it's actually closer to 140) So now I'm looking to do it via script, as you suggest. (I started an online JavaScript course to learn a bit about how stuff works xD)

What I'm trying to do is offer the player 3 randomly chosen skills from the database. And it turns out if I try to event this, I'll, like you mention above, end up with about a metric F ton of conditional branches and about triple the amount of switches and variable, so I believe scripting it will be the way to go. Thanks for the link to the script call list, this will def help along the way!
And it turns out if I try to event this, I'll, like you mention above, end up with about a metric F ton of conditional branches and about triple the amount of switches and variable
For the following summaries, I'll use:
  • C to represent the number of choices shown to the player (e.g. 3);
  • N to represent the total number of available choices (e.g. 140).
Other than 1 variable to store the player input for checking, I think the requirements for the ideas I suggested in my previous post would be as follows:
  1. Depends on which plugin you choose. With Himeworks Large Choices + Hidden Choice Conditions (assuming they're both compatible with MZ), I believe you would only require C variables. E.g. in a Script command (untested):
    JavaScript:
    // Hide all 140 choices.
    for (var n = 1; n <= 140; ++n) hide_choice(n, "true");
    // Show choices for rolled values.
    hide_choice($gameVariables.value(1), "false");
    hide_choice($gameVariables.value(2), "false");
    hide_choice($gameVariables.value(3), "false");

  2. [Edit 2: C variables for random rolls, and] N Items; no scripting or plugins.

  3. 2C variables: C for random rolls, plus another C for display texts.
Note that even for idea 4 you are left with N branches to check the output, unless you try to script all of that as well (I would not recommend that, but you do you).

Edit: 😴 sorry, I was forgetting about the specific context here. If you have the chosen skill ID in, say, variable 123, then you can replace the N branches after the input with a single Script command, e.g. (untested):
JavaScript:
const id = $gameVariables.value(123);  // chosen skill ID
const skill = $dataSkills[id];
const actor = $gameParty.members()[0];  // member index 0 = leader
if (!actor.isLearnedSkill(id)) {
  actor.learnSkill(id);
  $gameMessage.add(TextManager.obtainSkill.format(skill.name));
}
If using the scripted version of Show Choices, this could be included directly in the choice callback.
(assuming they're both compatible with MZ)
Shoot, I did it again. Saw @D-D-D-Dan uses MV on his profile, missed it's posted in MZ support.

If those plugins don't work with MZ, there are definitely ones that do if one Googles the appropriate terms. I am pretty sure the VisuStella Message Core incorporated some of that functionality, and there are others I've seen people mention.

Original thread: https://forums.rpgmakerweb.com/threads/need-some-help-for-setting-up-random-choices-in-dialogue.165949/