how do i make my scripted comands properly wait for the player?

I'm trying to make a plugin that reads dialogue from another file and excecute the right commands.
i know some of it can just be done in the in-game editor, but i want to have my events more organised as well as have pictures of the characters pop up on screen, which is done alongside the text printing. each with multiple possible versions and such.

i think i mainly got it for just text, but I also want to use movementroute in the scene's so the few large one's aside, it would be usseless if i had to break up the scene for every minor movement like just 1 'face up' or such. I would end up with minimal 5 scene object in one actual scene. and if i try to do some by editor to avoid that i would end up doing half of it in game anyway.

the problem is that the entire list of commands starts right from the start.
in the example i use for testing, this is the array/list

text1
text2
movementroute
text3

i can load them seperately. i get the actual text on a new page and wait for player input for the texts. But even though the movement route is 3th in line, it starts the moment i get to see the 1st text message.
and i can also watch the 3th text even though movement should be on wait for completion.

here is part of the code. an self made class DialogueManager manages all functions and holds the dialogue data.
DialogueManager.ReadScene = function(Chapter, Type, Id){ scene = $gameSystem._Dialogue[Chapter][Type][Id]; // scene holds an array with each element an action, this element is another array with needed info. for (var i = 0; i < scene.length; i++) { // for each line in the scene. var line = scene[i]; switch(line[0]){ case 0: // message DialogueManager.ReadTypePicture(line[2],line[3],line[4]) //shows character pictures $gameMessage.add(line[1]); $gameMessage.newPage(); $gameMap._interpreter.setWaitMode('message'); break; case 1: // movement route DialogueManager.ReadTypeMovementRoute(line[1],line[2],line[3]) break; } } };

and here is the part for the movement route.
DialogueManager.ReadTypeMovementRoute = function(target,listNames,params){// [1,target,list,params] // params: [wait for complete, repeat, skippable] var id = DialogueManager.findEventByName(target); // get event id. var list = []; //listNames : [["moveup"],["comand with param",[the params]],["end"]] example listnames array, needed to hold params together with comand for (var p = 0; p < listNames.length; p++) { // making list of commands list.push({ code: DialogueManager.GetCommand(listNames[p][0]), parameters: listNames[p][1] }); // parameters is just an array in tight order. } var route = {list:list, repeat:params[1], skippable:params[2]}; // making route obj if(id = -1){ $gameMap._interpreter._character = $gamePlayer $gamePlayer.forceMoveRoute(route); // giving list away } else { $gameMap._interpreter._character = $gameMap.event(id) $gameMap.event(id).forceMoveRoute(route); // giving list away } if(params[0] == true) $gameMap._interpreter.setWaitMode("route"); }

here is the actual scene object that i use as my test. though tecnichly it's more of an array.
[0,"test1","Sai V2","Ema V2",0], [0,"test2","Sai V2","Ema V2",1], [1,-1,[["ROUTE_MOVE_DOWN"], ["ROUTE_MOVE_DOWN"], ["ROUTE_MOVE_DOWN"], ["ROUTE_MOVE_DOWN"], ["ROUTE_MOVE_DOWN"], ["ROUTE_MOVE_DOWN"], ["ROUTE_MOVE_DOWN"], ["ROUTE_MOVE_DOWN"], ["ROUTE_TURN_UP"], ["ROUTE_END"]],[true,false,false]], [0,"test3","Sai V2","Ema V2",0],
the Sai V2 and Ema V2 names are names of pictures, one for body and other for face. the 0 or 1 after that is their position, determines their x value. they seem to work, except that just like movement route it al loads from the start so the images have the position of the last command 'test3'.
I have moved this thread from RPG Maker MV Support to Learning JavaScript.
A wait in the game is much more complex than most people think.

The game has a main loop that contains all game elements in need of updates, including every event and every refresh/update command. This loop is processed sixty times per second, once per frame.

The event command "wait" tells that loop to "skip processing this element for x frames", and all other variants work a similar way (skip element until <x> happens/is signalled).

If you place independent elements into the game loop, they will always be processed on the next frame. That is what obviously happens in your case.

You either need to place them into the same game loop object, or you need to tell their object (usually a game_interpreter_instance) to skip until later.

Unfortunately I can't tell you how that is done because I usually don't bother and use eventing for that, it's much easier that way than handling the code for the loop timing in javascript.
A wait in the game is much more complex than most people think.

The game has a main loop that contains all game elements in need of updates, including every event and every refresh/update command. This loop is processed sixty times per second, once per frame.

The event command "wait" tells that loop to "skip processing this element for x frames", and all other variants work a similar way (skip element until <x> happens/is signalled).

If you place independent elements into the game loop, they will always be processed on the next frame. That is what obviously happens in your case.

You either need to place them into the same game loop object, or you need to tell their object (usually a game_interpreter_instance) to skip until later.

Unfortunately I can't tell you how that is done because I usually don't bother and use eventing for that, it's much easier that way than handling the code for the loop timing in javascript.

I found a way around it.
I thought (and asked) if maybe using the code of the editor would help me. But when i was placing the code in a common event, I thought what if i used a loop in the editor. Give it a line every loop with an index instead of giving the whole scene in one scriptcall.

now i just need to put this in the editor:
variable DialogueIndex = 0; // id = 17 loop{ script(DialogueManager.ReadLine("Ch1","Main",0,$gamevariable.value(17)); variavle DialoguieIndex += 1; if(DialogueIndex >= 4 ) { // hardcoded number of lines in the scene Break Loop; } }

and ReadLine is basicaly the ReadScene, except it doesn't have the whole for loop and index is given as the 4th param instead.

DialogueManager.ReadLine = function(Chapter, Type, Id, index){ scene = $gameSystem._Dialogue[Chapter][Type][Id]; var line = scene[index]; switch(line[0]){ case 0: // message DialogueManager.ReadTypePicture(line[2],line[3],line[4]) $gameMessage.add(line[1]); $gameMessage.newPage(); console.log(line) $gameMap._interpreter.setWaitMode('message'); break; case 1: // movement route DialogueManager.ReadTypeMovementRoute(line[1],line[2],line[3]) break; } };

Thanks for the reply btw.
might not have been any direct help, but it has made me think outside of my plugin
which is how i found the solution.

Original thread: https://forums.rpgmakerweb.com/threads/how-do-i-make-my-scripted-comands-properly-wait-for-the-player.164138/