MZ Common Event Causing Game to Explode

I have *no* idea what is happening here

I have a common event with simple JavaScript that checks six variables, gets the highest, then turns a respective switch on for each one. Despite it working fine for several days, now whenever the event runs, the game chugs so hard it becomes unplayable. The code is only a few if statements, I can't imagine why the game is having so much trouble running it.

I'll post the code, I know it's ugly or whatever but it worked fine until recently! Is the for loop iterating infinitely?

(EDIT: The variables are referencing custom parameters from the Eli plugin)
You'll need to post screenshots of the common event and anything related to it running - such as the event that is calling the common event.

Alone, there is nothing we can do to help you with this.
You'll need to post screenshots of the common event and anything related to it running - such as the event that is calling the common event.

Alone, there is nothing we can do to help you with this.
The common event is set to run on startup, and the event itself is just turning all the switches off followed by the code I posted. The switches it flips each call a separate common event, which uses a visustella plugin to change the MC's traits. Here is an example:
I think I can be pretty confident in saying that the issue does not lie in the code you posted.

You still haven't shown the common event. How is it triggered? Is it autorun or parallel? Is it called from an autorun or parallel map event? That could be very important information.

It seems quite plausible that the trait change common events could be the cause, but you haven't given enough information.
I think I can be pretty confident in saying that the issue does not lie in the code you posted.

You still haven't shown the common event. How is it triggered? Is it autorun or parallel? Is it called from an autorun or parallel map event? That could be very important information.

It seems quite plausible that the trait change common events could be the cause, but you haven't given enough information.
It's not autorun or parallel, I have it set to be called on game startup using the VS Core Engine. I also have it called during a battle event but both have the same effect. I'll post a full screenshot of the event in the game itself.
So it's called once on startup? Is that equivalent to putting an event like this on the start map?

temp.pngtemp.png

And it's also called from a troop event?

Does it lag when the game starts, or only when it's called during battle?

What does the event that calls it look like?
So it's called once on startup? Is that equivalent to putting an event like this on the start map?

View attachment 358634View attachment 358635

And it's also called from a troop event?

Does it lag when the game starts, or only when it's called during battle?

What does the event that calls it look like?
I imagine they're the same. I have the VS Core calling it on startup. It lags both on startup and when used in battle. I'll post a screenshot from the plugin and of the event with Mr. Goblor the Goblin. The only difference between the battle and startup event is that the battle changes a custom parameter first and then runs the common event to see which value is highest, but like I said both cause the game to become basically unplayable.
In my experience game always lags when i forget to put a stopper on loops.. like wait 1 frame.
for what I see in your code is that the switch stays ON.
where is it turned off?

once you turn on a switch, you need to turn off the other or all 3 will run.

I made a switchGroup plugin, so only 1 can be on in this case, not all 3.
this can be useful in your case, and make it a group, if one of them is ON,
the other 2 will be false, (you can add that the other 2 is false, so they wont
be on. (6 extra lines).

but you keep them on, run all 3 common events.
This is unrelated, but I see your troop event is set to run once every 99 turns. Do battles even last that long? If you only want it to run once, you can set the repetition value to 0.

ShadowDragon's observation seems plausible – perhaps those trait common events are running every frame. If that's not what you want, the common events should each turn off their own switch.

Note that, by default, autorun common events do not run during battle. I don't know if VisuStella changes this though.
In my experience game always lags when i forget to put a stopper on loops.. like wait 1 frame.
I saw that suggested on google but it was seemingly only for parallel events. Where would I incorporate the wait command into the code?

(EDIT: So I got the wait command to work and that has actually stopped the chugging! That said the command still doesn't work the way it used to, and I have no idea why, but that's a start!)
This is unrelated, but I see your troop event is set to run once every 99 turns. Do battles even last that long? If you only want it to run once, you can set the repetition value to 0.

ShadowDragon's observation seems plausible – perhaps those trait common events are running every frame. If that's not what you want, the common events should each turn off their own switch.

Note that, by default, autorun common events do not run during battle. I don't know if VisuStella changes this though.
No they don't but I didn't know that you could just set it to 0 lol

Are you saying that, once the switch is turned on, the respective trait common event just runs over and over? I figured I was setting it so that when the original common event is called, a switch is flipped that in turn triggers a specific common event.
No they don't but I didn't know that you could just set it to 0 lol

Are you saying that, once the switch is turned on, the respective trait common event just runs over and over? I figured I was setting it so that when the original common event is called, a switch is flipped that in turn triggers a specific common event.
(EDIT for testing purposes I set all the trait common events to no trigger and the game is still chugging on startup. I guess that isolates the problem a little more?)
if you want to control the switch, you can use a conditional branch to run once.

if switch 1 = off
switch 1 is ON
do your stuff
else do nothing here until its off and recalled it)
end

while the trigger is none, it will never be called.
you can turn off switch 2 and 3 there too when its turned on.

but we have low screenshots how you try to connect them all,
so we need full screenshots, not cropped one, so we can see the entire link.

Original thread: https://forums.rpgmakerweb.com/threads/common-event-causing-game-to-explode.182102/