When do common events stop running their contents when turned off?

So let's say you have a parallel process common event triggered by a switch.  When the switch is ON, the event runs its contents from top to bottom (duh), and when the switch is OFF, the event stops running. My question is when you turn the switch off, does the common event stop immediately, or wait to finish all of its contents and then stop?  I guess another way to phrase it is 'When does the common event check to see if its trigger switch is off?'


I ask because if I have multiple common events triggered by the same switch, I want to know the implications of shutting off the switch for all of the common events at once.
I believe that when you turn the switch off, the common event will automatically stop whatever it's doing.
I believe the common event finishes the whole command set before stopping, but I'm used to reguar parallel processes, so I am not entirely sure. Having many parallel processes at the same time is however sometimes risky, you need to be careful of what you're doing.


An easy way for checking this : create a parallel common event with a command Wait:200 and a commande Message:"whatever". Create a character on the test map. Speaking to him turn the switch off. You'll see if the message appears or not after turning the switch off. If it does, it would mean that the common event finishes the command set.
I believe the common event finishes the whole command set before stopping, but I'm used to reguar parallel processes, so I am not entirely sure. Having many parallel processes at the same time is however sometimes risky, you need to be careful of what you're doing.


An easy way for checking this : create a parallel common event with a command Wait:200 and a commande Message:"whatever". Create a character on the test map. Speaking to him turn the switch off. You'll see if the message appears or not after turning the switch off. If it does, it would mean that the common event finishes the command set.



These only run in the menu, so no problems with risk, thanks!


Yes, I will try that test out! Great point
unfortunately you can't get a general answer - it also depends on the use of wait commands


Basically, if the command sequence is started, then it will run to the end - simply because there is no way to check the switch again before that. So a simple direct common event should not be interrupted.


However, the wait basically says "skip the execution of this event for the next X game cycles", and then the switch can be checked before continuing.


So your test with the wait will be different from a test of a longer command sequence that does not contain waits.
The event will stop after it has finished it's list, in most cases. If you perform an action that requests the map refresh (By default, this is adding/removing actors, changing switches/self-switches/variables, or changing the party's items), and then have the common event go into a waiting period (i.e. using the Wait command or displaying a message or something), then it would stop executing. This is because when the map is requested to refresh, the scene will go through all parallel common events and determine if they still need to be run, and if you disabled their switch and then set the common event to wait, it will be determined to not need to be run.


    But why does the event have to wait for it to stop executing?


Events and common events have their lists completed before anything else runs in the game. Nothing else happens while they're running. In order for the map scene to go through the list of common events to determine if they need to be run, no event can be running because otherwise that event would be updated instead of the scene. Having the common event wait will allow the scene to check and see that that event should no longer be running, and it will disable it.


    How long a wait would be needed to disable the event?


Waiting any amount is enough to stop the event if its switch is off. Waiting 1 frame will be enough to stop the event.


    But what about showing messages, choices, etc?


If you show a message, choices, or any other command that would cause an event to wait for its completion, that command will be the last thing executed before the event stops running. For example, 

Spoiler
xyzpNlL.png



The above screenshot will result in the text "Hello" appearing in a text box. When the text box is dismissed through user input, the event has already stopped executing. "This shouldn't appear." will not be displayed to the user.


    What actions refresh the map scene?


By default, the only actions that will refresh the map, and thus determine if common events should still run, are:

  • Adding actors to the party.
  • Removing actors from the party.
  • Adding or removing items from the party, including equipment.
  • Changing any switch's value.
  • Changing any variable's value.
  • Changing any self-switch's value, on any event.





    What are actions that will make the event wait?


By default, the list of actions that cause an event to wait are:

  • The wait command.
  • Showing a message.

    Inputting a number.
  • Selecting a choice.
  • Selecting an item.

[*]Transferring maps.

[*]Scrolling the map.

[*]Forcing a move route, if "wait for completion" is selected.

[*]Showing an animation, if "wait for completion" is selected.

[*]showing a balloon icon, if "wait for completion" is selected.

[*]Having all the party's followers gather on top of the player character.

[*]A battle action is forced, in a battle event.

[*]Playing a video.

[*]Displaying an image that is not already loaded into the game.




There may be others as well, as I did not inspect every line of the code, just took a glance at part of it.


    What do you mean an image not already loaded into the game?


If you haven't displayed a picture before, it isn't loaded into the game. Once a picture is loaded once, it's cached in memory for future uses. If the event's switch is off and you load a new, uncached picture into the game, the event will go into a waiting state, and since it's switch was disabled, it will stop.


    Ending Notes


Please keep in mind that this post can only discuss the default engine. If you have a plugin that requests that maps refresh under different conditions, or if any plugin makes events go into a waiting period at any other time, then the results will be different.
That was my fear, actually.. I would need to know which commands check and which don't. Pity.  I assume a Loop checks at the very end of the loop before reverting.


@Zalerinian thanks for that comprehensive answer wow

Original thread: https://forums.rpgmakerweb.com/threads/when-do-common-events-stop-running-their-contents-when-turned-off.67506/