MZ How to call Common Event within choices in JS

Well if you want i can explain to you in dms what exactly i am trying to do. Then you can also decide if i can share it in the forum
@IareaGuys , please avoid double posting, as it is against the forum rules. You can use the "Edit" function on your posts to add additional information you've forgotten or respond to multiple people. You can review our forum rules here. Thank you.
Even though the thread got a bit lost, I too would point to the suggestion in Caethyrils earlier post:
Spoiler: re your plugin code
As I mentioned in your previous thread, there is no need for a global interpreter reference...you can just reference the calling interpreter in the choice callback. E.g. using Function#bind:
JavaScript:
  $gameMessage.setChoiceCallback(function (responseIndex) {
    if (responseIndex >= 0)
      this.command117([1998 + responseIndex]);
  }.bind(this));
Also, [2000] is an array containing just 1 value: 2000.

$game_map._interpreter is likely not going to work in all cases (for example if your event runs as a parallel process, was called using "Call Common Event" or is used during battle), so replacing it with the "this" setup would probably be a good idea
Even though the thread got a bit lost, I too would point to the suggestion in Caethyrils earlier post:


$game_map._interpreter is likely not going to work in all cases (for example if your event runs as a parallel process, was called using "Call Common Event" or is used during battle), so replacing it with the "this" setup would probably be a good idea
Well the fight system is only gonna run on the map so i dont have any issues with the interpreter.
I am also 90% done with the code, so i dont want to switch to just to it in Common Events. I will maybe put more things into common Events, but not the entire thing, because that simply would make any sense.

So this is the common Event.
1690644347744.png

And this is my plugincode:
Code:
const PictureTestPluginName = "PictureTest";

PluginManager.registerCommand(PictureTestPluginName, "Choices", function () {
  let choices = ["Do1", "Do2", "Do3"];
  $gameMessage.setChoices(choices, 0, -1);
  $gameMessage.setChoiceBackground(2);
  $gameMessage.setChoicePositionType(2);
  $gameMessage.setChoiceCallback(function (responseIndex) {
    switch (responseIndex) {
      case 0:
        $gameMap._interpreter.command117([1998]);
        break;
      case 1:
        $gameMap._interpreter.command117([1999]);
        break;
      case 2:
        $gameMap._interpreter.command117([2000]);
        break;

      default:
        break;
    }
  });
});
And the problem is, that this breaks my loop and i dont know why. Maybe its because i am using command117 and not $gameTemp.reserveCommonEvent, but i tried that and it didnt work
If you use "Call Common Event", the interpreter will create a second interpreter, run the common event through that, and then continue with its own event list (to preserve its own settings).

By then using $game_map._interpreter, you are invoking "Call Common Event" on the original interpreter, interrupting and replacing any common event call that interpreter was currently waiting on.

In contrast, "this" is the interpreter that is currently executing your plugin command, so using that one should be save:
Spoiler
Code:
const PictureTestPluginName = "PictureTest";

PluginManager.registerCommand(PictureTestPluginName, "Choices", function () {
  let choices = ["Do1", "Do2", "Do3"];
  $gameMessage.setChoices(choices, 0, -1);
  $gameMessage.setChoiceBackground(2);
  $gameMessage.setChoicePositionType(2);
  $gameMessage.setChoiceCallback(function (responseIndex) {
    switch (responseIndex) {
      case 0:
        this.command117([1998]);
        break;
      case 1:
        this.command117([1999]);
        break;
      case 2:
        this.command117([2000]);
        break;

      default:
        break;
    }
  }.bind(this));
});
It says "this.command117 is not a function"

Edit: "It seems this refers to the gamemessage there."

Edit: Ah i see i forgot the bind(this)

Edit: Something weird i found out just now is that the first time i show choices they work fine, but then i show some text and after that the choices appear more at the bottom. Is there a way to strop that?

Edit: I have found a Solution in this thread https://forums.rpgmakerweb.com/index.php?threads/issue-with-choice-loop.150623/

Original thread: https://forums.rpgmakerweb.com/threads/how-to-call-common-event-within-choices-in-js.159767/