MZ SetChoiceCallback return not possible

Code:
  function TestCallback() {
    let res = null;
    $gameMessage.setChoiceCallback(function (responseIndex) {
      res = responseIndex;
      switch (responseIndex) {
        case 0:
          // Code
          break;
        case 1:
          break;
        case 2:
          break;
      }
    });

    return res;
  }

So i want to return the value of the responseIndex to an outer function, but somehow its not working and i don't know why? Am i missing something or is it not possible?
Variables are block-scoped, meaning res only exists inside the TestCallback function. If you want to use it elsewhere, you'll have to add it as a property on a persisting object, or store it in a Game_Variable.
Variables are block-scoped, meaning res only exists inside the TestCallback function. If you want to use it elsewhere, you'll have to add it as a property on a persisting object, or store it in a Game_Variable.
Okay, but when i return the value and do:

let returnedRes = TestCallBack();

it should work right?
Because for me somehow it doesn't
Okay, but when i return the value and do:

let returnedRes = TestCallBack();

it should work right?
Because for me somehow it doesn't
The reason for that is that at the point where you're returning res, the choice has been set up but the player hasn't actually made a choice yet. What you're setting up is the callback that'll be run when they do.
The reason for that is that at the point where you're returning res, the choice has been set up but the player hasn't actually made a choice yet. What you're setting up is the callback that'll be run when they do.
Ah that makes sense. Thanks

Original thread: https://forums.rpgmakerweb.com/threads/setchoicecallback-return-not-possible.166800/