Are you using any other plugins? If so, maybe share screenshot(s) of your Plugin Manager.
For testing purposes you can try using
console.log to show messages in the dev console. Press F8 to show the console during test. E.g.
Spoiler: your code with test outputs
JavaScript:
Game_Battler.prototype.addState = function(stateId) {
if (this.isStateAddable(stateId)) {
// DEBUG: check that it gets this far (e.g. because of State Resist or State Rate)
console.log('addState: state ' + stateId + ' can be added!');
if (!this.isStateAffected(stateId)) {
this.addNewState(stateId);
this.refresh();
}
else {
// Adiciona o State referenciado pela notetag <nextStack: X>
var nextStack = parseInt($dataStates[stateId].meta.nextStack, 10);
// DEBUG: show nextStack value in console
console.log('addState: nextStack = ' + nextStack);
if (this.isStateAddable(nextStack)) {
// DEBUG: notification that it can be added
console.log('addState: nextStack is addable!');
if (!this.isStateAffected(nextStack)) {
// DEBUG: notification of success
console.log('addState: adding next state');
this.addNewState(nextStack);
this.refresh();
}
}
}
this.resetStateCounts(stateId);
this._result.pushAddedState(stateId);
}
};
As you can see, these can be added wherever you like to check values and identify where the program is going and what is happening. You can remove them or comment them out when you get it working correctly.
👋
(Another, more advanced, option is using breakpoints, which work on the Source tab of the dev tools window: click a line number to define a breakpoint, and the app will pause when it hits that line of code. That tab offers controls to resume or step through subsequent code line by line.)
In case you're interested, here's an alternative implementation that is less likely to clash with other plugins. It works slightly differently to yours: it reapplies the original state (refreshing its turn count) when applying its "next" state. Also, since it's a patch, it will include all
addState modifications from other plugins that load before it.
Spoiler: patch plugin code
JavaScript:
// M05) State progression.
void (() => {
'use strict';
/** Name of notetag. */
const TAG_NAME = 'nextStack';
/** Anti-loop device. */
const chain = [];
/**
* @param {string} tag tag value from original state
* @returns {number} ID of next state to apply (0 = none).
*/
const getNextState = function(tag) {
return parseInt(tag, 10) || 0;
};
// Store current method for later reference.
const alias = Game_Battler.prototype.addState;
// Redefine method.
Game_Battler.prototype.addState = function(stateId) {
// If state is already here, also apply its "next" state
if (this.isStateAffected(stateId)) {
const next = getNextState(
$dataStates[stateId].meta[TAG_NAME]
);
if (next) {
chain.push(stateId);
if (!chain.contains(next))
this.addState(next);
}
}
chain.length = 0;
// And then invoke the original method~
alias.apply(this, arguments);
};
})();
This is modified from something I wrote for MZ, but I did a quick test in MV (same as before) and it seems to work. If you're using an old editor version then you may need to replace every
const here with
var to avoid syntax errors. [Edit: also swap the arrow function
() => { for a "proper" function
function() { in that case.]