MZ Battle plugins working on Battle Test but not Play Test

Hello, everyone!

As per title, I've been having this weird disconnect on how Battle Plugins work in Battle Test vs. Play Test.

The plugins work fine afaik in the database's battle test, nothing even shows on console. So I have things like action sequences (common events), special animations, yadda, yadda.

However, if I start the actual game on Play Test, some plugins don't turn on (I'm gonna asssume mostly visustella battle core) complete. To be most specific, I think it's only the regular attacks that aren't playing their action sequences.

Any guidance here would be appreciated!

To sum it up:
On a database battle test battle, everything works ok and no message shows up in the console.

But on a play test play test battle this show up in the console, and the attack animations don't play out normally anymore:
playtestbattleconsole.PNG
Maximum call stack size exceeded in onAddState suggests you have a state add notetag that's causing a recursive function call. What states do you have that do somethign when added?
Maximum call stack size exceeded in onAddState suggests you have a state add notetag that's causing a recursive function call. What states do you have that do somethign when added?

Currently, characters have a few test passives for the main mechanics rn:

The game has a system that checks TP % and adds one of four states based on that. Both player and enemies have those.
Player charaters have a passive state as an easy identification of who's doing what in battle
There's a passive state that triggers if a specific set of armor is equipped to give specific bonuses, etc.

These work in battle test though. I removed them and still got the error (but this time more plugins showed up):
playtestbattleconsole2.PNG


I also removed the passive states from the enemie, the console came out clean, however, the standard attack animations still ain't playing.

What bugs me is why none of this happens when I used battle test, what's different about its initialization compared to starting a regular game / play test?
What a head scratcher...
Currently, characters have a few test passives for the main mechanics rn:

The game has a system that checks TP % and adds one of four states based on that. Both player and enemies have those.
Player charaters have a passive state as an easy identification of who's doing what in battle
There's a passive state that triggers if a specific set of armor is equipped to give specific bonuses, etc.

These work in battle test though. I removed them and still got the error (but this time more plugins showed up):
View attachment 343674

I also removed the passive states from the enemie, the console came out clean, however, the standard attack animations still ain't playing.

What bugs me is why none of this happens when I used battle test, what's different about its initialization compared to starting a regular game / play test?
What a head scratcher...
There actually can be a difference between battle test and test play, as they use different data files and global presence identifiers.

Do you have any equipment bonuses that use a parameter value in their calculation?
Hmm, something interesting happened. Turns out if I turn off the passives the battle animation doesn't play as intended. I tested a battle test battle with one character not having the passive states and other having it and the one who had it played it normally.

Maybe there's a clue in the regular attack command event:

I'm using:

$gameActors.actor($gameTemp.lastActionData(2)).states().includes($dataStates[40]);

to determine which character is attacking, cuz I want each character to have an unique attack animation.

So character 1 has state 40 (Is Character #1, basically) and character 2 has passive state 41, and so forth...

This check works ok in battle test but it doesn't seem to work in play test. I assume there's no "lastActionData" or something?
Hmm, something interesting happened. Turns out if I turn off the passives the battle animation doesn't play as intended. I tested a battle test battle with one character not having the passive states and other having it and the one who had it played it normally.

Maybe there's a clue in the regular attack command event:

I'm using:

$gameActors.actor($gameTemp.lastActionData(2)).states().includes($dataStates[40]);

to determine which character is attacking, cuz I want each character to have an unique attack animation.

So character 1 has state 40 (Is Character #1, basically) and character 2 has passive state 41, and so forth...

This check works ok in battle test but it doesn't seem to work in play test. I assume there's no "lastActionData" or something?
No, if that were the case your error would be something like "lastActionData is not a function". The error you're currently having is caused by a function calling itself.

This is a completely separate thing, but if you want each character to have a unique attack animation, why not give them a unique attack skill and set their "attack skill" trait to the respective ID?
No, if that were the case your error would be something like "lastActionData is not a function". The error you're currently having is caused by a function calling itself.

This is a completely separate thing, but if you want each character to have a unique attack animation, why not give them a unique attack skill and set their "attack skill" trait to the respective ID?

Thank you for the unique attack as a trait suggestion, I honestly totally forgot traits had that option! Looks better too than having a bunch of conditionals in the base attack, appreciated!

I've been testing around and it seems that the passive that changes based on TP could be the one?

Each character has 4 different states to check if TP is around the 25%, 50%, 75%, 100% range.
Each one looks something like this:

<JS Passive Condition>

if (user.tp >= 25 && user.tp <= 49){

condition = true;

} else {

condition = false;

}

</JS Passive Condition>



<Hide State Popup>

<Repeat Animation: 15>

They work fine in battle test, but I checked they're not even triggering in Play Test, the state animation isn't playing.
1) it hasn't been mentioned so far, but how exactly do you playtest?
are you starting a new game or are you loading a saved file?
please always test with new game if errors happen

2) battletest and ingame battles have basically only one difference:
The battletest skips several setup functions to start the battle in a faster way.
That has been known to disrupt plugins that are suddenly missing their correct setups (similar to loading a savefile can load an old configuration that is no longer compatible).

In your case that would mean that one of those setups has the wrong configuration, resulting in the battle only working if the battletest skips the misconfigured setup.

I can't tell you which plugin that would be (never used MZ so far), but that is where you should start checking what went wrong.
1) it hasn't been mentioned so far, but how exactly do you playtest?
are you starting a new game or are you loading a saved file?
please always test with new game if errors happen

2) battletest and ingame battles have basically only one difference:
The battletest skips several setup functions to start the battle in a faster way.
That has been known to disrupt plugins that are suddenly missing their correct setups (similar to loading a savefile can load an old configuration that is no longer compatible).

In your case that would mean that one of those setups has the wrong configuration, resulting in the battle only working if the battletest skips the misconfigured setup.

I can't tell you which plugin that would be (never used MZ so far), but that is where you should start checking what went wrong.
I start new games, I'm working on getting all the mechanics functioning first, so it's easy to start a new game just for testing purposes. I'm gonna to a deeper dive today and try to troubleshoot some more.
then post screenshots of your entire plugin manager with all your plugins and in which order you have them. Someone might be able to find a known problem there.
I think I've found out where's the issue: apparently, it's the passive state note for the enemies.

They're supposed to be affected by the TP check State (If 25%, add state, if 50% add a different state and so forth). They all look like this, with the TP threshold changed:


Code:
<JS Passive Condition>


if (user.tp >= 25 && user.tp <= 49){


  condition = true;


} else {


  condition = false;


}


</JS Passive Condition>

Looks like VisuStella has a thingy to check infinite loops on passive states but I don't get it why this is only affecting enemies rn.

So every enemies has this <Passive State: 1, 2, 3, 4> on. That works on battle test but gets into an infinite loop (I assume) once the game initializes normally.

The thing is, I need a way to check the TP progress of enemies and give them proper states as this will be a main mechanic for the combat. The passive works as intended for the players no matter what, but it only works for enemies under battle test.

I wouldn't mind another solution on how to apply this to enemies that's streamlined cuz every enemy in the game will have to have this.

Current Plugin Order:
plugin1.PNG

plugin2.PNG

plugin3.PNG
The thing is, I need a way to check the TP progress of enemies and give them proper states as this will be a main mechanic for the combat. The passive works as intended for the players no matter what, but it only works for enemies under battle test.

I wouldn't mind another solution on how to apply this to enemies that's streamlined cuz every enemy in the game will have to have this.
Why exactly does it need to be a state? Where exactly do you need to check the TP progress of the enemies? Maybe there's a way to do it without a state. If it's something you use in damage formulas, for example, you can probably use b.tpRate() instead (that gives you tp divided max TP as a fraction). On the other hand, if the only reason for it to be a state is because you want a state icon to appear, then there's probably some way to make a state icon appear that's not linked to any state (after all, buffs and debuffs do that).

I do have one idea on what might cause the stack overflow error, though it's purely speculative. When the passive state is added, the game needs to check the user's TP. In the base engine, that's just looking up a simple number, but I have no idea what VisuStella (or any other plugin on your list) might have changed about the process. Perhaps one of your plugins needs to fetch the states applied to the actor before the TP can be determined, and if fetching the states includes adding any passive states, then you would have a situation where adding that passive state needs to add the state before it can be added and you get into an infinite loop.

So, do any of your plugins affect how TP works in any way?
Why exactly does it need to be a state? Where exactly do you need to check the TP progress of the enemies? Maybe there's a way to do it without a state. If it's something you use in damage formulas, for example, you can probably use b.tpRate() instead (that gives you tp divided max TP as a fraction). On the other hand, if the only reason for it to be a state is because you want a state icon to appear, then there's probably some way to make a state icon appear that's not linked to any state (after all, buffs and debuffs do that).

I do have one idea on what might cause the stack overflow error, though it's purely speculative. When the passive state is added, the game needs to check the user's TP. In the base engine, that's just looking up a simple number, but I have no idea what VisuStella (or any other plugin on your list) might have changed about the process. Perhaps one of your plugins needs to fetch the states applied to the actor before the TP can be determined, and if fetching the states includes adding any passive states, then you would have a situation where adding that passive state needs to add the state before it can be added and you get into an infinite loop.

So, do any of your plugins affect how TP works in any way?

There's multiple effects tied to the TP bar rate, so it's not just damage formulas, it's buffs, debuffs, animations, effects, etc. So far the easiest way I've found to keep track of everything is by having states.

Afaik, no plugin affects the way TP works.

Thanks for the suggestion, I'll have a look at that.

EDIT: If that is the case (can't see Visustella) could I write a quick plugin to bypass that? Or is there a way to emulate the initialization skip done in battle test? Maybe if it's possible for me to just write the state conditions on the enemy notetags, instead of them relying on a passive state, etc.
Cannot say anything definitive either. From the earlier error stacks it looked like calculating maximum MP would be part of the problem. (What exactly does the "mpdeath" plugin again?^^)
Edit: It is likely that the MMP calculation just was the process that broke the ceiling on the almost full stack without being part of the issue.

It is possible that the game is caught in a loop trying to resolve conflicting states. I don't know if it helps, you could try to use this script to attempt to get some info (either by putting it as a plugin at the end of the list, or copy&pasting it into the developer console before triggering the error):
Spoiler
JavaScript:
function RefreshLog() {
    this.initialize(...arguments);
}

RefreshLog.prototype.initialize = function(battler) {
    this._battler = battler;
    this.clear();
};

RefreshLog.prototype.clear = function() {
    this._history = [];
    this._states = new Map();
};

RefreshLog.prototype.log = function() {
    let stateString = JSON.stringify(this._battler);
    if (!this._states.has(stateString)) {
        this._states.set(stateString, this._states.size);
    }
    this._history.push(this._states.get(stateString));
};

RefreshLog.prototype.inspect = function() {
    let array = this._history;
    let repetend = 0;
    let longestRepeat = 0;
    // Find Repeating Part:
    for (let i = 1; i <= array.length / 2; i++) {
        let success = true;
        for (let k = 2 * i; success && k <= array.length; k += i) {
            for (let l = 0; success && l < i; l++) {
                success = (array[array.length - k + l] === array[array.length - i + l]);
            }
            if (success && k > longestRepeat) {
                repetend = i;
                longestRepeat = k;
            }
        }
    }
    // Extract Differences:
    let stateObjects = [];
    this._states.forEach((value, key) => stateObjects[value] = JSON.parse(key));
    let repetendDifferences = [];
    for (let i = 0; i < repetend; i++) {
        let current = stateObjects[array[array.length - repetend + i]];
        let previous = stateObjects[array[array.length - (i > 0 ? repetend : 0) + i - 1]];
        repetendDifferences[i] = {};
        for (let key in current) {
            if (JSON.stringify(current[key]) !== JSON.stringify(previous[key])) {
                repetendDifferences[i][key] = JSON.stringify(current[key]);
            }
        }
        for (let key in previous) {
            if (!current.hasOwnProperty(key)) {
                repetendDifferences[i][key] = "<deleted>";
            }
        }
    }
    return {
        BattlerName: this._battler.name(),
        BattlerState: this._battler,
        RecursiveRefreshCount: array.length,
        RepetendLength: repetend,
        StateTrace: repetendDifferences,
    };
};


Object.defineProperty(Game_BattlerBase.prototype, "refreshLog", {
    get() {
        if (!this._refreshLogSecretValue) {
            Object.defineProperty(this, "_refreshLogSecretValue", {
                value: new RefreshLog(this),
            });
        }
        return this._refreshLogSecretValue;
    }
});

Game_BattlerBase.prototype.refresh = (alias => function() {
    this.refreshLog.log();  // First Log first
    alias.call(this);
    this.refreshLog.log();  // Second Log after "state resist"
})(Game_BattlerBase.prototype.refresh);

Game_Actor.prototype.refresh = (alias => function() {
    try {
        alias.call(this);
    } finally {
        // Usually the last step in the refresh chain (if this is the last plugin)
        if (this.refreshLog._history.length > 4) {
            console.log("Refresh Log:\n------------------------");
            console.log(this.refreshLog.inspect());
            console.log("------------------------");
        }
        this.refreshLog.clear();
    }
})(Game_Actor.prototype.refresh);

Game_Enemy.prototype.refresh = (alias => function() {
    try {
        alias.call(this);
    } finally {
        // Usually the last step in the refresh chain (if this is the last plugin)
        if (this.refreshLog._history.length > 4) {
            console.log("Refresh Log:\n------------------------");
            console.log(this.refreshLog.inspect());
            console.log("------------------------");
        }
        this.refreshLog.clear();
    }
})(
    Game_Enemy.prototype.hasOwnProperty("refresh") ?
    Game_Enemy.prototype.refresh :
    function() { Game_Battler.prototype.refresh.call(this); }
);
Late Edit: Replaced the script to print excessive recursive refresh calls regardless of whether an actual error is thrown (did not consider that any error may get catched and suppressed by VisuStellas plugins)

This won't prevent any errors, but should print out an expandable object at the end of the error message containing the battler state and (with some luck) a list of which properties have changed with each refresh of the battler ("StateTrace").

Other than that, Is what you are using the minimum amount of passive states to make the error appear?
Cannot say anything definitive either. From the earlier error stacks it looked like calculating maximum MP would be part of the problem. (What exactly does the "mpdeath" plugin again?^^)

It is possible that the game is caught in a loop trying to resolve conflicting states. I don't know if it helps, you could try to use this script to attempt to get some info (either by putting it as a plugin at the end of the list, or copy&pasting it into the developer console before triggering the error):

Other than that, Is what you are using the minimum amount of passive states to make the error appear?

Oh, I think you're onto something! Removing the mpdeath plugin does make the passive check run normally again!

I want enemies (and only the enemies) to be able to die to either HP or MP damage for the game, so I pieced around something to achieve that, though I have very little coding experience, so I most likely screwed something up then.

Spoiler: mpdeath
Code:
Game_Battler.prototype.refresh = function() {
Game_BattlerBase.prototype.refresh.call(this);
if ((this.hp === 0 || this.mp === 0) && this.isEnemy()) {
this.addState(this.deathStateId());
} else {
this.removeState(this.deathStateId());
}
};

Game_Interpreter.prototype.command332 = function(params) {
    const value = this.operateValue(params[1], params[2], params[3]);
    this.iterateEnemyIndex(params[0], enemy => {
        enemy.gainMp(enemy, value, params[4]);
    });
    return true;
};

Game_Interpreter.prototype.changeMp = function(target, value, allowDeath) {
    if (target.isAlive()) {
        if (!allowDeath && target.mp <= -value) {
            value = 1 - target.mp;
        }
        target.gainMp(value);
        if (target.isDead()) {
            target.performCollapse();
        }
    }
};

Game_Interpreter.prototype.command333 = function(params) {
    this.iterateEnemyIndex(params[0], enemy => {
        const alreadyDead = enemy.isDead();
        if (params[1] === 0) {
            enemy.addState(params[2]);
        } else {
            enemy.removeState(params[2]);
        }
        if (enemy.isDead() && !alreadyDead) {
            enemy.performCollapse();
        }
        enemy.clearResult();
    });
    return true;
};

Then I added this to the Dead State:

<JS Passive Condition>

if (user.mp == 0){

condition = true;

} else {

condition = false;

}

</JS Passive Condition>
That code does look quite suspicious.

Your custom mpdeath plugin is adding the death state when an enemy's HP or MP reaches 0, and removing the death state when both HP and MP of an enemy is nonzero, and also removing the death state from an actor no matter what their HP and MP are (in other words, it looks like it will make actors immortal). In addition to that, it's likely wiping out part of the functionality of other plugins, since you don't alias the methods properly.

Then your passive state condition is specifying that the death state should be added to anyone (enemy or actor) if their MP is 0, and removed if their MP is nonzero.

So, for example, what happens when an actor's MP is 0? Passive States adds the death state (because their MP is 0), and and mpdeath removes it (because they're not an enemy).

I would say that you should use either your plugin or a passive state condition for this, not both. I think a passive state condition can likely do it by itself, though I'm not 100% sure that it would handle the collapse animation when they die of MP damage. If the passive state condition isn't good enough on its own, and you don't want to figure out how to fix you custom plugin, you could give my AltDeathState plugin a try – I don't know if it's compatible with Yanfly though, and I also don't know if it performs the collapse animation properly (the animation just never occurred to me when I implemented it). If you want to fix your mpdeath plugin and delete the passive state condition, I (or others) can probably help with that too.
i wouldnt make death itself a passive state. Visustella's passive states dont work like states normally do in many ways. isStateAffected() doesnt work on them by design and id imagine all kinds of ingame checks such as when the battle should end would fail.

I want enemies (and only the enemies) to be able to die to either HP or MP damage for the game, so I pieced around something to achieve that
since you wanted it to only effect enemies, it would have been simpler imo to make an enemy version of refresh to kill the enemy if either their HP or MP was 0 instead of changing the battler version that gets ran on both enemies and actors and checking if the battler is an enemy. as already noted, youve changed refresh to only be able to kill battlers that have either their HP or MP at 0 AND are an enemy, which means an actor cant die

You didnt touch command 333 as far as i can see and the change you made to command 332 doesnt do anything. you made that interpreter changeMp() function, but never used it and used the battler's gainMp() anyways with arguments its not going to be able to use.
This depends on your game and if its a mechanic ofc, but you might want to make an enemy revive() that also checks for mp being 0 and sets it to 1 so that an enemy killed via MP damage that revives without MP recovery doesnt just fall over again
Had to make some corrections to my last post.

Aside from the issues Solar_Flare and Robro33 mentioned, the plugin does look like it should work on first glance.

Your plugin is replacing Game_Battler.prototype.refresh, and there may be a chance you are nullifiying changes made to that function by other plugins higher on the plugin list.
If you have not done so, you could try to start the game with "mpdeath" disabled and type the name of the function into the console to verify that no other plugin has modified it.
If some plugin did, you could try to place "mpdeath" somewhere above it in the plugin list.

An alternative would be to use an alias (i.e. create a snapshot of the previous version of the function, and then calling that snapshot to essentially pasting the lost code back into the function).
This is not guaranteed to prevent compatibility issues, but it avoids probably the most common cause:
JavaScript:
const GameBattlerRefreshBeforeMpDeath = Game_Battler.prototype.refresh;
Game_Battler.prototype.refresh = function() {
    GameBattlerRefreshBeforeMpDeath.call(this);
    if (this.mp === 0 && this.isEnemy()) {
        this.addState(this.deathStateId());
    }
};

When states can be added and removed automatically based on the battlers state, some state combinations may be irreconcilable. Even without any plugins you can create an infinite recursion by giving the death state a "State Resist: Death" trait and then killing a battler.

It is still possible that some kind of effect combination temporarily raises the battlers mp or hp above 0, reviving the target, then dropping hp/mp back to 0 and killing it again.

Edit: As Robro33 mentioned, passive states do not count as states inflicted on the target.
With death state specifically, it will do what it says on the state page, but it will not kill the target or make the target count as dead when applied as a passive state from what I have seen.
Hey guys, thank you very much for all the information and advice!

I spend last night trying to tackle this, and yup you guys were right, that code did make the player characters immortal. That went completely over my head cuz my dummies for battle tests usually don't deal damage so that's something I'd figure out only in-game.

Another Fen's code made it more streamlined and fixed the immortal issue. However, the loop was still going on and affecting the main mechanic tied to TP and Passive States. I guess the issue is on how VisuStella handles addState, all I know is that moviment the plugin order unfortunately did no good.

I did managed to sorta bypass the issue by switching "this.addState" to "this.addNewState" but now the death animation doesn't play out when the enemy dies to MP damage. At least the TP mechanic goes back to normal that way, for whatever reason.

My goal is to have all the mechanics I intend for the project to be working as close as possible to what I envision to at least present the project and maybe show it to people I could hire in the future to make a more solid code.

I thank you guys very much cuz with this I think I'm able to work on an alpha-esque version of the project. This isn't entirely solved but it doesn't break the other stuff as much anymore.
I think you just mixed up the parentheses in your plugin version, the refresh function itself should have been fine.

I don't know if this is relevant here, but after some tests in VisuStellas sample project I would recommend also checking for hp/mp/tp values outside the allowed range, e.g. using
user.mp <= 0 over user.mp == 0
user.tp < 25 over user.tp >= 0 && user.tp < 25
user.tp >= 75 over user.tp >= 75 && user.tp <= 100
etc.

(Passive conditions seemed to be checked before those values get corrected, and trying to add another state while passive states were in an inconsistent state seemed to cause issues sometimes).


addNewState is generally not designed to be used on its own (it does not check if the state is already applied for instance). If this approach does not cause any other problems you could try also add this._result.pushAddedState(this.deathStateId()); and see if this fixes the collapse issue.

Original thread: https://forums.rpgmakerweb.com/threads/battle-plugins-working-on-battle-test-but-not-play-test.178553/