MZ Show Choices Scripting

Hello,

I have been working on learning scripting using the RPG MAKER Script Calls document and other various tutorials. I am starting to get the hang of it, however I am completely lost when it comes to 'Show Choices'. I do not know if this changes anything, but I am calling this script from a 'Common Events'. I apologize if this has been addressed before on the forum, but I was unable to find a solution.

The Problem:
I am attempting to store the choice 0 or 1 in variable 40 so that I can reference the variable later and call additional messages. I have posted the code I have written below. While it prompt's the choice menu, it seems to already move onto the next section (as if I already selected 'Continue'.

Can someone please advise what I am doing wrong with my script? Also if you can please help me understand why this.setWaitMode('message'); isn't forcing the game to allow the player to make a choice before moving forward.

Please let me know if I need to clarify anything.
Thank you for your help.

JavaScript:
//Check if energy is at or below 0.. if so warn player
if ($gameVariables.value(1) <= 0) {
    $gameMessage.add("Are you sure you want to continue?");
    $gameMessage.setChoices(['Continue', 'Stop'], 0, -1);
    $gameMessage.setChoicePositionType(2);
    $gameMessage.setChoiceCallback(n => {$gameVariables.setValue(40, n);});
    this.setWaitMode('message');
} 

//selecting Continue option
if ($gameVariables.value(40)==0){
    $gameMessage.add("\\n[2] gained sword making experience.");
    this.command115(); // exit
}

//selecting No option
if ($gameVariables.value(40)==1){
    $gameMessage.add("\\n[2] stops training for now.");
    this.command115(); // exit
}

rpgmakerMVScriptingDemo.png
Hello,

I am returning with a solution, perhaps this well help a fellow noob in the future some day.
The problem is that I was calling all of the code above as one script. The interpreter does not wait for anything so you need to utilize multiple scripts. I'll paste a screenshot to illustrate what I mean.

The first script runs the choice segment, the second script then checks if variable 40 was updated.


1702881287102.png

Original thread: https://forums.rpgmakerweb.com/threads/show-choices-scripting.163779/