MV Stop parallel common event when menu/dialogue box is open.

Is there a way to put a bit of javascript that automatically sets a switch ON/OFF to pause a parallel common event, so it doesn't run when menu/dialogue is open?
So I would not have to constantly flip that switch manually in every event that has dialogue? (and no idea how I'd even do it for the menu with normal eventing)

Basically: When the function to open the menu is called it should turn off a switch and back on when the close function is called... and same for the dialogue window!

Thank you!
the common events should automatically stop in the menu, unless you installed a plugin with a menu interpreter. Because only the map and the battlescreen have interpreters by default, no other screen - that is why the menu has to close if you use an item with a common event - the CE can't be processed in the menu and the engine has to return to the map before it can be processed.

as for the event dialogue - that is a bit more complex.
while it is possible to write a plugin that stops whenever a show text is processed, it gets more complex the more commands you include and additionally depends on what the parallel process is supposed to be doing.

Can you describe what that common event is doing?
there is a way, the best way I think off, is on Window_Message active
to switch the switch on and on terminate, turn it off something like this:

JavaScript:
function flipSwitch(id, state) {
    $gameSwitches.setValue(id, state);
};

const _WindowMsg_startMsg = Window_Message.prototype.startMessage;
    Window_Message.prototype.startMessage = function() {
        flipSwitch(100, false);
        _WindowMsg_startMsg.call(this);
    };

const _WindowMsg_terminateMsg = Window_Message.prototype.terminateMessage;
    Window_Message.prototype.terminateMessage = function() {
        flipSwitch(100, true);
       _WindowMsg_terminateMsg.call(this)
    };

change the ID of 100 in terminate and start message to your common Event ID
and it automatically swap if there is a message or not.

Edit:
for Main menu it need some extra code, but same process though =)

alternative (all windows that has it)
JavaScript:
function flipSwitch(id, state) {
    $gameSwitches.setValue(id, state);
};

const _windowBase_open = Window_Base.prototype.open;
    Window_Base.prototype.open = function() {
        _windowBase_open.call(this);
            flipSwitch(100, false);
};

const _windowBase_close = Window_Base.prototype.close;
    Window_Base.prototype.close = function() {
        _windowBase_close.call(this);
            flipSwitch(100, true);
};

see what works 🙂
@Andar
Ohhhh, great to know!
What I need the stop for is an event that basically ticks down a hunger viariable over time, so it has a wait command at the start and afterwards reduces the variable and also calls another common event to check if it dropped below a certain number and does stuff if it did etc. It would be annoying if the hunger reduces while you are in a menu / dialogue, since it would force you to rush reading stuff etc.

@ShadowDragon
Thank you so much, I'll give that a try!
Edit: It worked well, thank you!
So I would not have to constantly flip that switch manually in every event that has dialogue? (and no idea how I'd even do it for the menu with normal eventing)
fwiw, whenever any dialogue or cutscene plays in my game, I already have a common event that I run at the start and end of the cutscene. It does number of things, and since it's a common event, it's easy to modify behaviors of other events in any cutscene that plays by simply modifying the cutscene common event.

The point I am making is that, you could consider just having a similar arrangement.
It basically uses a switch. When I run it the first time (start of a cutscene):

if cutscene switch is off:
do entering cutscene things, turn cutscene switch on.

then when I run it a second time (and the end of the cutscene):
if cutscene switch is on:
do exiting cutscene things, turn cutscene switch off.
Edit: Just in case someone finds this later on... A small adjustment to the script: The true/false needs to be switched for the message start and terminate, otherwise the common event will only run during dialogue! At start it needs to be false, at terminate it needs to be true.
I edit the code to swap it, so its my bad.

if it works, thats good, but like TheAM-Dol said can work too, as you can
select some parts that can be off if you don't mind other things to run.

so there are alternate methods for more control, the way I did with Window_Base
is that every window uses the open and close just set the switch to false,
otherwise to ON.

so it also really depends on your workflow, mechanics etc, so use what
works best for you.

Good luck on your project 🙂
Another thing you could do is make your common event skip out if there's a dialogue on the screen. If you only want it to stop when you can actually see dialogue, you can use the following script condition in a Conditional Branch:

Code:
$gameMessage.isBusy()

That will be true if there's a message box or any kind of selection box (choice, item, etc) on the screen. If you want it to stop whenever a non-parallel event is executing, you can use the following script condition:

Code:
$gameMap.isEventRunning()

Just put a check for one of those conditions at the top of your common event and add an Exit Event Processing command (maybe a wait command too) inside it.
Code:
$gameMessage.isBusy()
That will be true if there's a message box or any kind of selection box (choice, item, etc) on the screen. If you want it to stop whenever a non-parallel event is executing, you can use the following script condition:
I completely forgot this method, as I did used !$gameMessage.isBusy() for an evented method
to run, otherwise do nothing, However, I did read about the other, but not used before,
so I don't know if it works for menu's as it isn't specific an event? unless ran by it?
I'm not quite sure what you're asking? isEventRunning is true if a non-parallel event is running, so it's only useful to check it in a parallel event. (I'm not sure if it detects common events set to autorun.) But what does menus have to do with any of this? No events are running when you're at the menu (although, isEventRunning would probably return true if you reached the menu as a result of an event command, rather than via input).
@TheAM-Dol Yes, it's a good solution and I thought about it, but I honestly just don't want to remember that for every event I create and I fear missing a few... haha. These solutions are just easier and save me some nerves and time, even if it's just a few seconds per event XD

@ShadowDragon Thank you so much! The script works well! (also I edited my post again to not make it confusing!)

@Solar_Flare Oh! That's a great solution. I'll remember that for the future. Thanks for sharing!
Understandable.
A note about my cutscene common event is that it originally started as just a way to add visual borders to the scene to indicate that the player is not in control - basically like letter boxing the game window. So if I ever forgot to include it - either at the start or the end of a cutscene - it would be easy for me to notice because the pictures aren't showing up or being erased.
It was only later that I realized I could use that same event to also adjust some game logic during cutscenes as well.

I got into a habit pretty quickly to always start events that are intended to be cutscenes with:
common event: cutscene
comment: ----- (I use this as a spacer to indicate the end)
common event: cutscene

Spoiler: Practical use example
This is copied from one of my events just to show a practical way of how I lay out my events. Likely unnecessary information since you are opting for a different approach, but I decided to include this for you or anyone else who may be considering this approach in the future.

Code:
◆Common Event:--->CUTSCENE-MANAGER
◆Control Switches:#0186 BypassCutsceneWrapUp = ON
  ◆Comment:+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  ◆Comment:+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  ◆Change Items:Fish + 1
  ◆Set Movement Route:This Event (Wait)
  :                  :◇Transparent ON
  ◆Set Movement Route:Player (Wait)
  :                  :◇Turn Down
  :                  :◇SE:001-Jump (90, 100, 0)
  :                  :◇Jump:+0, +0
  ◆Plugin Command:ShowIconBalloon 260 on Player
  ◆Comment:+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  ◆Comment:+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  ◆Control Variables:#0013 META-RandomVariable = Random 0..4
[...]
  ◆If:META-RandomVariable = 4
    ◆Plugin Command:TE AddBust Fidel 1100 440 13
    ◆Play SE:001_FiddleSpeak (100, 100, 0)
    ◆Text:NamePlates_Set1(0), Window, Bottom
    :    :It would be a lot cuter if it had eyebrows\w[5].\w[5].\w[5].
    ◆
  :End
  ◆Comment:+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
◆Common Event:--->CUTSCENE-MANAGER

It's been slightly truncated since it rolls a random variable to change what the player says.

The Cutscene common event is "--->CUTSCENE-MANAGER
" because the arrow and caps make it stand out very obviously when scrolling through the list of common events. Were I man who could plan better, I would have made this common event #1 considering how frequently it gets used. Sadly, I didn't come up with the cutscene common event until much later in development, so I needed to devise a way to easily identify it from all the other common events.

The "BypassCutsceneWrapUp" switch tells my cutscene common event to ignore some camera position reset commands. This switch gets turned off automatically when running the cutscene common event a second time.

You can see here, I often use ascii art comment lines as breaks in the event commands to make it easier for me to read.

Original thread: https://forums.rpgmakerweb.com/threads/stop-parallel-common-event-when-menu-dialogue-box-is-open.181179/