I am trying to create a javascript function in my custom plugin that initiates a conversation in a loop. Text is displayed, and the user is offered the choice to continue or exit. If the user decides to continue, the text is displayed again with the same two options. This repeats until the user selects to exit, at which point the conversation ends.
My final version will of course be more complex, but this example boils down the problem area for me.
I have the logic working fine in RPG Maker MV:
However, I cannot get this same functionality from my javascript. Here is my attempt:
This freezes up because the loop executes infinitely. The loop does not wait for user input between iterations like the one in RPG Maker itself. If I change it to a for loop with a set number of iterations, like 5, it will simply spit out "Some text that repeats." 5 times in a row.
Any ideas on how I can get this javascript code to behave like the RPG Maker logic would be greatly appreciated. Thanks.
My final version will of course be more complex, but this example boils down the problem area for me.
I have the logic working fine in RPG Maker MV:
However, I cannot get this same functionality from my javascript. Here is my attempt:
Code:
Game_System.prototype.endlessConversation = function() {
$gameMessage.add("Start of dialogue:");
while (true) {
$gameMessage.newPage();
$gameMessage.add("Some text that repeats.");
$gameMessage.setChoices(["Continue", "Exit"], 0, -1);
$gameMessage.setChoiceCallback(function(n) {
if (n === 1) {
break;
}
});
}
}
This freezes up because the loop executes infinitely. The loop does not wait for user input between iterations like the one in RPG Maker itself. If I change it to a for loop with a set number of iterations, like 5, it will simply spit out "Some text that repeats." 5 times in a row.
Any ideas on how I can get this javascript code to behave like the RPG Maker logic would be greatly appreciated. Thanks.