"Common Event calls exceeded the limit" via doors

I didn't realize there was a limit to common event calls. Up until now, I've been using common events to make doors, that way I don't have to go back and edit every door if I need to change how the doors themselves work. "A good developer sets it up so they only have to call one bit of code instead of calling a new line of code for the same thing" and all that. But... it seems that I hit the limit of common event calls by doing this. Is there some way to make it so that I don't?
It seems as though I only hit the limit when going through doors in the same map. Say, for example, I have a castle map, and both floors of the castle are on the same map, so I use a common event to teleport the character between them vs the floors being on separate maps. I assume this means that changing maps resets the limit? Is there a way to implement that "reset" between same-map runs?
It would help if we had some clue as to what you're talking about.

Where are you seeing this? Does your game crash and give this error? Does it happen when you load the map or when you try to activate the event?

Where's a screenshot of the event(s) in question?

"A good developer sets it up so they only have to call one bit of code instead of calling a new line of code for the same thing"
I understand the desire to keep things modular, but RPG Maker kind of expects simple things to be contained within the actual map event. Especially with the ability to make the quick-create transfer event...what do you anticipate having to change across your events?

If you find yourself calling several common events from inside other events, you're probably doing something in an overly complicated way.

A quick Google I just did indicates this error comes from calling 100 events without exiting out of them completely, so you're definitely doing something wrong.
It's happening after a player has gone through several teleport events on the same map. Essentially, I'm running an event that that sets a map ID, X, and Y value for the actual teleport itself, then runs a "door" common event that makes the door open, the player move through the door, then fades to black, teleports the player, then fades in. Here's the series of common events.
Door CE.png

So, basically, what's happening is I'm running these four common events for a door. If the door teleports the character to a different map, then it seems to reset the common event counter. If the door teleports the character to somewhere in the same map, it has now incremented the common event counter by 4, and there's a max of 100. When it reaches 100, it errors with "common event calls exceeded the limit" then crashes.
So, I wondered if there was a way to make the common events end or reset the common event counter after the events are run. There's really no need for those events to stay active/in counter, but I don't know if there's a way to do that.
Why is Fade In, Fade to Black and Teleport three separate common events? Why can't you have all three of those commands in the same common event?
Why is Fade In, Fade to Black and Teleport three separate common events? Why can't you have all three of those commands in the same common event?
Because I sometimes use fade in and fade out separately. I use the Tint Screen feature for the fade in and fade out, so if I want something to be dark, I can have a different fade in effect for that darkness. Or if I need it to be night, I can fade in and have it be the night colors. Stuff like that. That way I can call whatever I need, instead of having to have 20 different events that all just have one minor difference.

Unfortunately, from what I'm understanding, RPG Maker might force me to set it up like that every time... which will become a huge pain should I find myself needing to add a night/darkness/whatever scene in an area I've already coded... and have to edit all the doors, then figure out which ones are edited and which aren't... Especially on the larger city maps...

Either way, even if I did put them all in one common event, the issue would still persist (though, albeit, likely lessened). If I build a castle, for example, I generally put all of the rooms of the castle on a single map. Yes, I doubt I'd use up all 999 maps even if I didn't, but I can't be sure. If I split up the castle and monastery maps I have into separate maps, I'd be adding a full 30 new maps in... But, because I'm not changing maps, it's apparently not "releasing" the common events, and it eventually builds up to the 100 limit if players wander on the map long enough and go back and forth through areas.

One of my testers had this error happen to them, and all they did was explore the whole of the castle. If my castle has 10 rooms, and each door uses 4 events (and you go in and out of a room, thus hitting 8 events), just going into each room is already going to compile the 100 events. It's true that putting everything into one event will lower that down to just like 20-30... but there's still a chance a player could get lost and wander enough to hit that 100 cap... And the last thing I want is to release a game with a huge bug simply because I "couldn't figure out a fix."

If there is no fix, I can start re-editing doors to not use common events... But that's going to take a lot of work to essentially undo what I had hoped would be a system to avoid having to re-edit stuff constantly...
I don't think that's what's causing the error.

I think you have common events that are calling each other. Like CE 1 calls CE 2 and CE 2 calls CE 3 then CE 3 calls CE 1.

Calling a common event from within a common event appears to be the only thing that increases the "depth" variable, and when that hits 100, it throws the error.

So you need to look elsewhere for the cause.
I don't think that's what's causing the error.

I think you have common events that are calling each other. Like CE 1 calls CE 2 and CE 2 calls CE 3 then CE 3 calls CE 1.

Calling a common event from within a common event appears to be the only thing that increases the "depth" variable, and when that hits 100, it throws the error.

So you need to look elsewhere for the cause.
I don't have anything else, though... And it's only happening on the maps where the player is on a single map. For example, it occurs if you walk around enough in the monastery, which is all one map, like this:
Monastary.png

Each door/path uses those common events from above. Eventually, as you wander, it builds up to the limit. This does not happen at all, though, if you transfer between maps.

EDIT: Tested teleporting on the same map over and over using only the teleport common event, and... huh... apparently there might be more to this, cause it didn't cause an error after 100 teleports... What could be causing the problem, them?
Please give us a full screenshot of the door/transfer event, and in the future please do not crop away half of the event.

To be clear: the event properties are half the event and are as important to understand what is happening as the content of the event.

And Shaz is right - only a recursive event call can cause such an error.
If you do not remember where you have this, then that does not change the fact that it is somewhere - might not be in the doors, but somewhere you have a recursive effect, or a parallel event calling too many common events too fast or something like that.

You might want to follow the link to "bughunting" in my signature
It's as Shaz said. It's not about the total number of common events that have been called--it's about the depth of your nested common event calls. That error suggests that you've somehow got a continuous chain of 100 common events calling each other, which can't be explained by the information that you've shared with us. Either that, or you've got a plugin that is somehow screwing with things.

That aside, I do agree with the other posters in that you are being excessive in your usage of common events. There's rarely a time when it would (realistically) be beneficial to have a common event that only contains one event command. The 4 common events that you've showed us could easily be combined into 1 common event.
Please give us a full screenshot of the door/transfer event, and in the future please do not crop away half of the event.

To be clear: the event properties are half the event and are as important to understand what is happening as the content of the event.

And Shaz is right - only a recursive event call can cause such an error.
If you do not remember where you have this, then that does not change the fact that it is somewhere - might not be in the doors, but somewhere you have a recursive effect, or a parallel event calling too many common events too fast or something like that.

You might want to follow the link to "bughunting" in my signature
That's the thing... I haven't cropped out anything. Everything I've shown is the entire thing. The only bit that is cropped is the teleport event. 100% of what I have in those common events is otherwise shown. Here's the whole of the teleport event if it helps.
Teleport.png

It's as Shaz said. It's not about the total number of common events that have been called--it's about the depth of your nested common event calls. That error suggests that you've somehow got a continuous chain of 100 common events calling each other, which can't be explained by the information that you've shared with us. Either that, or you've got a plugin that is somehow screwing with things.

That aside, I do agree with the other posters in that you are being excessive in your usage of common events. There's rarely a time when it would (realistically) be beneficial to have a common event that only contains one event command. The 4 common events that you've showed us could easily be combined into 1 common event.
I might consider doing that. Still, what is running is exactly what I've posted. There is nothing else. What's really annoying me right now is that I've even attempted to test it all again, and the error is not showing up, no matter what I do... And that makes no sense to me... I swear RPG Maker somehow keeps changing how it works, because I've had this issue plenty of times before where I code two things exactly the same and it works in one instance, then it doesn't in another... Or, I ask for help on how to fix a bug, only to then test for that bug again, and get no bug... despite doing the same thing... It's driving me absolutely batty.

Edit: Here is the actual event that is first calling the "door" common event, if that helps in any way.
Door Event.png


Edit 2: Here's another reason why I have the common events broken up like I do. Sometimes, I need a fade out, something might happen before the teleport, and/or something might happen before the fade in.
Broken Up.png
Please give us a full screenshot of the door/transfer event, and in the future please do not crop away half of the event.

To be clear: the event properties are half the event and are as important to understand what is happening as the content of the event.
Andar explicitly explained what is missing in your screenshots.
Andar explicitly explained what is missing in your screenshots.
Door Event 1.png

So, something like this?
So, something like this?
yes, but for the other event, the one where you have the move routes and call the other common events and so on - we still don't know how that is triggered.
yes, but for the other event, the one where you have the move routes and call the other common events and so on - we still don't know how that is triggered.
Door Event 2.png

This is literally everything... unless I'm misunderstanding something? First is the actual event on the page. The second is the common event "Door" that the first event calls. The third is the "Fade In", fourth is "Fade to black", fifth is "Teleport". There's nothing else involved in the events that I know of...?
Here is a little plugin that could possibly help you troubleshoot this. Please paste this code into a new .js file, put it in your plugins folder, and add it to your project through the plugin manager:

Spoiler: Code
JavaScript:
/*:
* @target MZ
* @plugindesc Trace excessive common event depth
* @author Arthran
*
* @help
* ------------------------------------------------------------------------
* Terms of Use
* ------------------------------------------------------------------------
* Can be used in any type of project. Credit is not required.
*
*/

Game_Interpreter.prototype.command117 = function(params) {
    const commonEvent = $dataCommonEvents[params[0]];
    if (commonEvent) {
        const eventId = this.isOnCurrentMap() ? this._eventId : 0;
        if ($gameTemp.isPlaytest() && this._depth >= 29) {
            console.warn('Excessive common event depth: ' + (this._depth + 1));
            console.log('Origin event: ' + eventId);
            console.log('Common event: [' + params[0] + '] ' + commonEvent.name);
        }
        this.setupChild(commonEvent.list, eventId);
    }
    return true;
};

It will start warning you in the console once your Common Event depth is 30 or higher, and it will tell you which common event is being called, as well as the ID of the original map event that started the chain (provided that it's not an event from a different map than the current one). It should help shed some light on what's going on.

Spoiler: Example
1687675301477.png

In order to see the information, you'll have to open the developer console (Press F8 and then click on the 'Console' tab at the top). Unfortunately, it may not help if the cause of your issue is another plugin. But if the cause of the issue is something that you're doing, it should help track it.

*edit* Just figured that I should clarify that this is for RPG Maker MZ. Your profile says that you use MV, but you posted in the MZ forum, so I wasn't sure which engine to write the plugin for.
Yes, but in your first screenshots we couldn't even see if the door event was a map event or a common event, and that makes a big difference.

First, a little bit of background info:

1) on map change, all common events are reset. That is why the mapchange prevents the error you got.

2) you should NOT use the same structure on transfers to another map, EVER.
More precisely, on a map change the transfer command should be the last command of the transfer event, NEVER followed by other commands.
That is because map events get deleted as soon as the map is deleted, and it is more or less random chance if anything after the transfer command is ever processed.
(no, there are rules to this as nothing is truly random on the computer, but I don't want to go into the difference between instant and multiframe commands)

No matter how you like your common event nesting, those two rules take precedence over everything!



Back to the problem at hand.
Theoretically, there is no direct iteration visible in them. But you still have a recursive iteration somewhere or you would not get the error.

That basically leaves three different possibilities:
1) some other events create the recursion instead of the transfers, either on map or in common events.
And due to the large number of common events I can't even guess the probability for this, you'll have to check every map event to make a list of what events are called and check them, as well as checking all common events for parallel trigger as that could also cause problems like this.

2) you have a combination of plugins that broke the engine somewhere
Usually plugins should rarely be connected to common events, but there are some plugins that modify them for one or another reason. We would need to see your entire plugin list (including their order) to guess if there is a conflict somewhere.

3) Problem with the internal transfer function
This is something that one of the better programmers will have to dive into the code to check.
The default behaviour of the transfer command is to check if the transfer goes to a different map or not, then branch into two different behaviours.
If the transfer goes to a different map, everything should be reset, the map deleted and the next map loadfed.
If the transfer remains on the same map, it should only change the local coordinates and then resume.

However it mioght be that the function has a bug where the transfer does NOT correctly return to the above adress, exactly because it expects the reset and almost no one uses that deep common event nesting for transfers.

If that is the cause, then it is a bug in the engine that has so far escaped notice because no one nested those transfers.
But someone needs to trace the engine core files to check that.


EDIT: the post above with the warning plugin should help identify if other events are the cause, better than my suggestion
If you like, you can zip up your project and send it to me. I'll take a look and see if I can figure out where the issue is happening.

In case you have any paid plugins, I have Visustella, but if you have any others, you can copy your project folder then go into the copy, delete the paid plugins, and zip up that copy project and send to me. I doubt I'll need to actually run it.

For your one-line common events, you could set a switch to say you want a fadeout/fadein, just like you've set variables for the transfer. Then you can put fadeout/transfer/fadein into a single common event, using conditional branches to say whether to do the fadeout/fadein or not. But that isn't going to resolve your problem.
I mean, I would say a "good programmer," above all else, uses system resources judiciously. I love common events, but I try to save them for when it counts. Most fancy things I do by setting switches on maps.
It still just doesn't seem logical that you'd need to have common events for fading out, fading in, and transfer when all of that is automatically done within the one Transfer Player event command.

I don't really understand the relation between all that and tint screens, they shouldn't have to be related. Are you saying that walking through a doorway to transfer to another map looks different depending on what map it is?

As far as the events on a map, I did point out in my first reply that it wasn't about leaving the map to "release" events, but about actually finishing the event processing without getting 100 calls deep. I think this is just a case where you need to let the software work the way it's intended to, a bit 😉
Apart from common event 86, which calls itself, I couldn't find anything like what I was expecting. And we don't believe that's the culprit because nothing triggers it.

If you delete that common event, or at least remove the command inside it to call itself, does it still happen?

Can you add the plugin Arthran provided in post 15 and see what it says?

Original thread: https://forums.rpgmakerweb.com/threads/common-event-calls-exceeded-the-limit-via-doors.158656/