Waiting for a message to be clicked on in a loop - using scripting

Hi all,

I'm new to using RPG maker mv and am trying to send multiple messages with a dialog choice one after the other, however it currently doesn't display any of the choices it just displays each of the text boxes. It is only after all three have been clicked on that it will display the choices.

this is my current code

this.setWaitMode('message'); for (let i = 0; i < 3; i++) { let PlayerRolls = $gameVariables.value(7) console.log("in loop") $gameMessage.newPage(); $gameMessage.add("Pick your roll \!"); $gameMessage.setChoices(PlayerRolls, 0, -1); $gameMessage.setChoiceCallback(function(n) { const index = PlayerRolls.indexOf(PlayerRolls[n]); PlayerRolls.splice(index,1); $gameVariables.setValue(7, PlayerRolls) console.log(PlayerRolls) })};

if anyone could point me in the right direction that would be great thanks! and if there is any more information needed please let me know.
Moved to: Learning Javascript
Looking at what you have compared to the syntax in the script call list, it specifies the setWaitMode() function call must be in a separate script command from the one that constructs the choices.

You also have yours before you've made the choices, not after - I haven't done this manually through code, so I don't know if that's breaking it.
Hi, thanks for your reply.

From some more testing I haven't found any difference from moving the setWaitMode, either to another script or moving it after the choices. I think my main issue here is that the script is evaluated in its entirety without the game being able to act upon it. And so although the text is added to presumably a queue and therefore all three can be displayed, the choices are just overwritten. However I'm still not sure why the choices only appear on the third text box.

I don't mean this is as a definitive, this is just my guess at what could be the problem.

I've ended up changing it to where the loop is done by using two event pages, one to run this code and another to then check if its been run 3 times and then either return to the other page or move on.
I am happy that you found a solution that works for you. I just wanted to chime in that in your code snippet I don't really see a reason to not just do it with event commands. In general you will make your live easier when using event commands for simple stuff.
@eomereolsson thanks for your reply,

My main reason was that the number of elements in the array reduces by one each time the choices are displayed and I wasn't sure there was a way to display 3 then 2 then 1 option in the array without having to write three versions in the event commands. I may just be missing something. Also something that is missing from my snippet is that there is some more game logic after each choice is made and so it can't just collect the three choices and then move on, after each choice it has to branch to another event page, and then when it returns it has to display the correct number of choices.

I also wasn't sure if there was a way to splice the array in an event command without using the script snippet for the set operation.

This is my current code for it:

let PlayerRolls = $gameVariables.value(7); let score = $gameVariables.value(8); this.setWaitMode('message') $gameMessage.newPage(); $gameMessage.add("Pick your roll"); let pointer = this $gameMessage.setChoices(PlayerRolls, 0, -1); $gameMessage.setChoiceCallback(function(n) { let roll = parseInt(PlayerRolls.splice(n,1)); $gameVariables.setValue(7, PlayerRolls); let brunoArr = $gameVariables.value(9); const brunoIndex = Math.floor(Math.random() * (brunoArr.length - 1)); let brunoRoll = parseInt(brunoArr.splice(brunoIndex,1)); $gameVariables.setValue(9, brunoArr); pointer.setSelfVariableValue($gameMap._mapId, pointer._eventId, 10, brunoRoll); pointer.setSelfVariableValue($gameMap._mapId, pointer._eventId, 11, roll); }); this.setSelfSwitchValue($gameMap._mapId, this._eventId, 5, true);

As I mentioned I'm very new to all this, so it is extremely likely that I just have some gaps in my knowledge with how event commands can achieve this in a nicer way, but this is where I'm at for now.
My main reason was that the number of elements in the array reduces by one each time the choices are displayed and I wasn't sure there was a way to display 3 then 2 then 1 option in the array without having to write three versions in the event commands.
Writing three versions in event commands would probably take fewer lines than doing out all of the $gameMessage complexity in code 😉

You could also use a plugin like Aloe's conditional choices to do it all within the choice event command.
Hi @ATT_Turan , thanks for your reply.

One issue I'm having with using the choices event command is that it cannot index the array e.g. \V[7][0] will output '12,16,4[0]' and not '12'.

this is my current code using Aloe's conditional choices:
Most of the logic is still within scripts, its just now also within event commands.

1681224335557.png


1681224384916.png

1681224857675.png


The actual game logic itself I think I've managed to port over, its just the message issue.
I don't know if that style of notation will be correctly parsed by MV's engine at all.

You might have to either store that value in a separate, non-array variable, or use something like Eli's Escape Codes that offer an eval code (so you'd just do $gameVariables.value(7)[0]).
Hi @ATT_Turan , thanks again for your reply,

I tried using Eli's Escape Codes plugin and it worked in correctly indexing the array

1681227814829.png


However there seems to be some kind of conflict with another plugin i'm using YEP_SelfSwVar, as no matter how I seem to order the plugins the data structure that stores the selfSws and SelfVars is undefined.

I think I'll just stick to the script heavy version as moving away from the array to individual vars seems like its not worth the trouble.

Thanks very much for all the help.

Original thread: https://forums.rpgmakerweb.com/threads/waiting-for-a-message-to-be-clicked-on-in-a-loop-using-scripting.156533/