Script messages don't wait for player to read before running more code

I have a similar problem as described in this RPG ACE thread but can't find the answer for RPG MV.

https://forums.rpgmakerweb.com/index.php?threads/show-text-script-call-not-working.95097/

Problem is that 'var 5' sets to False, and the sound plays before message 1 is even finished showing on screen and often message 2 won't even load. in VX ACE you can use 'wait_for_message' to fix thins. How do I fix i in RPG MV?

my script example:

set a var 5 to TRUE;
$gameMessage.add("Blah blah blah.");

get an item;
play a sound effect;
set var 5 to FALSE;
$gameMessage.add("more Blah blah blah.");
When you show text using an event command, it adds it to the message, but it also makes the interpreter wait until the text is no longer displayed before moving onto the next command. If you are going to show messages via script, then you also need a method, via script, to make the interpreter wait until the text is no longer displayed.

Why are you doing this via script? All of the above can be done with event commands.
I need to do it by script because I am changing the player image based on 2 separate variables: Mood and Clothing. There are 25 (so far) possible combinations so I pass the Mood and Clothing as variable to a common event that selects the correct face image. Then the script is called and it writes the text part of the message and displays it on the screen. It works perfectly... except I'm missing the script line to force the interpreter WAIT as you mentioned. I can't find any way to do that in the Scripting page

-docs.google.com/spreadsheets/d/1-Oa0cRGpjC8L5JO8vdMwOaYMKO75dtfKDOetnvh7OHs/edit#gid=0

I 'can' force it to wait by having an empty text window, but that is really dorky... I know that in VX ACE you can use wait_for_message

Is there a similar line for MV?
this.setWaitMode("message")
I have tried:

$gameMessage.add("my text here");
this.setWaitMode("message");

and it works.

Thanks for the help! Really, I don't know how you javascript geniuses know all this stuff!
Experience with the MV core engine in short. It's the same as speaking a language - you have a set of rules you know and make a sentence from them. This is the same. A set of rules we know and use.
Hello, @Poryg. I'm currently working in RPG Maker MZ and I need exactly the same as the OP:

- Message
- Wait for reading
- Get an Item
- Play a Sound

I'm writing a Plugin because I need to manage the Inventory for my own and I know very wall JavaScript, but I can't handle very well the RPG Maker's engine.

I tried
JavaScript:
$gameMap._interpreter.setWaitMode('message');

And:
JavaScript:
this.setWaitMode('message')

But nothing happens, it calls everything together.

What am I doing wrong?

This is my code:
JavaScript:
        $gameMessage.setBackground(1);
        $gameMessage.setPositionType(2);
        $gameMessage.add(message);

        $gameMap._interpreter.setWaitMode('message');

        $gameParty.gainItem(item, 1);

        AudioManager.playSe({
            name: 'PickupItem',
            pan: 0,
            pitch: 80,
            volume: 80,
        });

Thank you in advance, and I hope you can help me =(
Use a common event instead of a plugin for this particular call. Have the message stuff in first script command and the add item + sound is second script command. That's what I can say out of the box as an idea. Writing a plugin would be way too tedious.

If you want to have it all in a plugin, you can make the plugin call the common event when you need.
If you want to have it all in a plugin, you can make the plugin call the common event when you need.
I had done something like that, but it didn't convince me. Code here, events there...

I'm writing a plugin because I want to get the events as clean as possible. So, in my events use "Plugin Commands", so easy, so clean, like this:

InventoryManager.png


And that Command does several things...

I found a workaround doing this:
JavaScript:
GameInventory.wait(callback) {
    setTimeout(() => {
        if (!GameInventory.isPicking()) {
            callback();
        } else {
            GameInventory.wait(callback);
        }
    }, 100);
}

And calling it, like this:
Code:
GameInventory.addNewItem(itemType, itemId) {
    GameInventory.setIsPicking(true);
   
    // A lot of stuffs...
    // ...
   
    // Waiting until "this._isPicking" is false
    GameInventory.wait(function () {
        $gameMessage.add('It's done');
    });
}

Look, I know this is not the best way, but it works as expected. By the way, pickup an item it's instantaneous, and the wait function works great, like a parallel event but in my plugin.

EDIT: Thank you for you quick reply, you was very kind. I hope my answer help you in whatever you want to do via script :LZSsmile:

Original thread: https://forums.rpgmakerweb.com/threads/script-messages-dont-wait-for-player-to-read-before-running-more-code.95896/