MV Using more then one set of choices in a JS script call

I am attempting to include choices and message windows in complex logic I can only write with JS (heavy use of multi dimensional arrays)
The issue I'm running into is nothing works if I include more then one set of choices or multiple message box in the entirety of a script call. Having a single set of choices or a single message box works fine, but If I include another anywhere in the code even in conditionals that wont trigger (only one textbox will display when the code runs, but many exist within the code) nothing works at all.

here's an example of how I implement choices in my code:
JavaScript:
var itemID = $gameVariables.value(6);
var mainItemArray = $gameVariables.value(7);
var selectedItem = $dataItems[itemID].name;
var foundItemArray = [];
var foundItemChoices = [];
var foundAtIndex = [];

for (var count = 0; count < mainItemArray.length; count++) {
    
    if (mainItemArray[count][0] === selectedItem) {
        
        foundItemArray.push(mainItemArray[count]);
        foundAtIndex.push(count);
        
    }
    
}

for (var nextCount = 0; nextCount < foundItemArray.length; nextCount++) {
    
    foundItemChoices.push(foundItemArray[nextCount][5]);
    
}

$gameMessage.setChoices(foundItemChoices, -1, -1);

$gameMessage.setChoiceCallback(function(responseIndex) {

    $gameVariables.setValue(5, foundItemArray[responseIndex]);
    $gameVariables.setValue(8, foundAtIndex[responseIndex]);

});


Am I doing something wrong? is it impossible to include more than one set of choices or more than one text window in a script call?
it seems that even when I put 2 script calls next to each other in an event I have the same problem. Separating them with anything else besides a script call works, but this is to limited for my needs.
is there any way around this?
Thanks for your time / help!
You haven't told the interpreter to wait for the user to make a choice before moving to the next command. Try adding this line to the end of your script call:

this.setWaitMode('message');
Note that interpreter wait time only applies between commands, so if you want to script multiple choices in a row, you will need to break those into multiple Script commands.

In case it helps, here's an example copied directly from the MV / MZ Script Call List:

// Set choices to A, B, C; default C, no cancel $gameMessage.setChoices(['A', 'B', 'C'], 2, -1); // Set background: Dim $gameMessage.setChoiceBackground(1); // Set position: Center $gameMessage.setChoicePositionType(1); // On choice, set variable #1 equal to the selected index $gameMessage.setChoiceCallback(n => { $gameVariables.setValue(1, n); }); // Wait for a choice to be selected this.setWaitMode('message');
So ill still have to dump all my variables to game data. Unfortunate but still a lot better than what I had assumed before. Will try this. Ty very much.

Does this mean its still impossible to have choices after a series of conditionals?

Example:

JavaScript:
var a = 15;

if (a < 10) { // series of choices  }
else if (a > 10) { // series of choices }

because achieving something like this is the goal
Each Script command is its own unit, evaluated as a single chunk of code. As mentioned, the interpreter only checks its wait time/mode between commands. So for multiple choices you will need to split them into multiple commands, otherwise only the most recent choice settings will apply.

If you really want to script it all, I think you'll need to either:
  1. Add "Show Choices" commands to the interpreter via scripting; or
  2. Bypass the interpreter entirely, e.g. a plugin for a custom scene or map choice structure.
Option 1 would probably be much easier, but still awkward. Here's a relevant script call from the MV / MZ Script Call List, to give you some idea of what would be involved:
Spoiler: Insert Event Commands
var self = interpreter;
var pre = self._list.slice(0, self._index + 1);
var post = self._list.slice(index + 1);
var com = commands;
self._list = pre.concat(com, post);[/icode]
Game_Interpreter interpreter
  • Interpreter reference (this in a Script command).
(command)[] commands
  • Array of objects, each with these properties:
    • code: event command code.
    • indent: command indent, used for branches.
    • parameters: command parameters.

Notes:

This deliberately creates a new command list. Simply inserting new commands into the current interpreter list will mutate the current event's database record for the rest of the play session.

The RPG Maker MZ Script Call Reference has a list of event command codes and parameters. Most of these also apply to RPG Maker MV.
Example:
// In a Script command: insert Show Text, Wait, Show Text var pre = this._list.slice(0, this._index + 1); var post = this._list.slice(this._index + 1); var i = this._indent; var com = [ { code: 101, indent: i, parameters: ['Actor1', 1, 0, 0] }, { code: 401, indent: i, parameters: ['Mwahaha! HAHAHAHA!'] }, { code: 230, indent: i, parameters: [120] }, { code: 101, indent: i, parameters: ['Actor1', 1, 0, 0] }, { code: 401, indent: i, parameters: ['...well, this is awkward.'] } ]; this._list = pre.concat(com, post);
Thank you very much for all of your help

Original thread: https://forums.rpgmakerweb.com/threads/using-more-then-one-set-of-choices-in-a-js-script-call.149240/