MV setWaitMode not working (resolved)

$gameMessage.setChoices(
[$gameParty.members()[0].name(),
$gameParty.members()[1].name(),
$gameParty.members()[2].name(),
$gameParty.members()[3].name(),
$gameParty.members()[4].name(),
$gameParty.members()[5].name(),
$gameParty.members()[6].name(),
$gameParty.members()[7].name(),
'cancel'], 0, 8);
$gameMessage.setChoiceCallback(0,select_member(0));
$gameMessage.setChoiceCallback(1,select_member(1));
$gameMessage.setChoiceCallback(2,select_member(2));
$gameMessage.setChoiceCallback(3,select_member(3));
$gameMessage.setChoiceCallback(4,select_member(4));
$gameMessage.setChoiceCallback(5,select_member(5));
$gameMessage.setChoiceCallback(6,select_member(6));
$gameMessage.setChoiceCallback(7,select_member(7));
this.setWaitMode('message');

this is my js code.

when I use

"this.setWaitMode('message');"

it show me up "this.setWaitMode is not a function",

and when I use
"$gameMap._interpreter.setWaitMode('message');"

It show up next text even I didn't select anything.

first, I try to find setWaitMode function in "this", but it was "undefined".

How can I resolve it?

thank you for read it. and please help me.

============================================================

I resolve it. choiceCallback need only single argument.
thank you.
oh I resolve it thank you.
setChoiceCallback need a single arg.
It sounds like a scope problem:
  1. The error means that this does not have a function named setWaitMode. That implies it's not an interpreter instance.

  2. In a Script command this points to the corresponding interpreter instance, but this is a keyword whose value varies depending on context:

  3. Parallel events are not processed by the main interpreter $gameMap._interpreter, so telling the main interpreter to wait will not affect the Parallel event.
setChoiceCallback should be called once, with a single argument: a function that will be run when a choice is made. The callback function accepts 1 argument: the index of the selected choice. E.g.
JavaScript:
var names = [0,1,2,3,4,5,6,7].map(function(n) {
  $gameParty.members()[n].name();
});
names.push("cancel");
$gameMessage.setChoices(names, 0, 8);
$gameMessage.setChoiceBackground(0);
$gameMessage.setChoicePositionType(2);
$gameMessage.setChoiceCallback(function(n) {
  select_member(n);
});
this.setWaitMode("message");
This assumes a select_member function already exists in the current scope.
It sounds like a scope problem:
  1. The error means that this does not have a function named setWaitMode. That implies it's not an interpreter instance.

  2. In a Script command this points to the corresponding interpreter instance, but this is a keyword whose value varies depending on context:

  3. Parallel events are not processed by the main interpreter $gameMap._interpreter, so telling the main interpreter to wait will not affect the Parallel event.
setChoiceCallback should be called once, with a single argument: a function that will be run when a choice is made. The callback function accepts 1 argument: the index of the selected choice. E.g.
JavaScript:
var names = [0,1,2,3,4,5,6,7].map(function(n) {
  $gameParty.members()[n].name();
});
names.push("cancel");
$gameMessage.setChoices(names, 0, 8);
$gameMessage.setChoiceBackground(0);
$gameMessage.setChoicePositionType(2);
$gameMessage.setChoiceCallback(function(n) {
  select_member(n);
});
this.setWaitMode("message");
This assumes a select_member function already exists in the current scope.
thank you very much.

and I got a new problom.

$gameMessage.add is not working.


$gameMessage.add('test'); // it works
$gameMessage.setChoices(['i!','am!'],0,1);
$gameMessage.setChoiceCallback(n => {
$gameMessage.add('test'); // it doesn't work
});
$gameMap._interpreter.setWaitMode('message');

is add() not work in choiceCallback function?
It works, but the message is cleared after selecting a choice so the text is cleared before it can display:
JavaScript:
Window_ChoiceList.prototype.callOkHandler = function() {
    $gameMessage.onChoice(this.index());
    this._messageWindow.terminateMessage();
    this.close();
};

Window_ChoiceList.prototype.callCancelHandler = function() {
    $gameMessage.onChoice($gameMessage.choiceCancelType());
    this._messageWindow.terminateMessage();
    this.close();
};
If you want to change that then you can copy these methods into a .js file, edit it so terminateMessage happens before onChoice in both cases, then import it as a plugin. I don't know if that will have bad side-effects.

If you describe why you are trying to do this, someone may be able to suggest a simpler approach? E.g. for a custom dialogue system it is generally easier to build an array of event commands (Show Text, Show Choices, etc) and feed that into the existing engine.

Original thread: https://forums.rpgmakerweb.com/threads/setwaitmode-not-working-resolved.153938/