[MV]Error with Adding State via JS

Hello,

I've been having a strange error with the addState script call. Basically, addState doesn't work if I've previously added and removed the state (the console log test explains it best). The problem even persists into a new, blank project. I tested through events and the console. I also uninstalled and reinstalled MV through steam. Has anyone else had this problem or knows of a possible solution? I have seen this thread and it might be the same issue, but I'm not sure.

Thanks for reading!

Spoiler: console test
1636960178881.png
Spoiler: event script test
1636960053986.png
Spoiler: event command test
1636959955278.png
how many actors and how many states do you have?
can you give screenshots of your database?
Hi there!

Wow, I never tried to do something like that.
But as I can see, the Game_Interpreter does the state add/remove in a way just a little bit different than doing it with script call:

JavaScript:
// Change State
Game_Interpreter.prototype.command313 = function(params) {
    this.iterateActorEx(params[0], params[1], actor => {
        const alreadyDead = actor.isDead();
        if (params[2] === 0) {
            actor.addState(params[3]);
        } else {
            actor.removeState(params[3]);
        }
        if (actor.isDead() && !alreadyDead) {
            actor.performCollapse();
        }
        actor.clearResult(); // THIS
    });
    return true;
};

After he adds or removes a state, he calls "actor.clearResult()".
I really can't explain why, because I'm always confused regarding the Game_Action and Game_ActionResult classes.
But maybe that have something to do with the .removedStates property of the actor:

JavaScript:
Game_Battler.prototype.removeState = function(stateId) {
    if (this.isStateAffected(stateId)) {
        if (stateId === this.deathStateId()) {
            this.revive();
        }
        this.eraseState(stateId);
        this.refresh();
        this._result.pushRemovedState(stateId); // Here
    }
};

Game_ActionResult.prototype.pushRemovedState = function(stateId) {
    if (!this.isStateRemoved(stateId)) {
        this.removedStates.push(stateId); // Here
    }
};

I think maybe the _result of the actor is storing the removed states in the removedStates property. So somehow, that can be the "why" it will not work.

Try to call the $gameActors.actor(1).clearResult() after adding and removing states in your script call tests to see if it will work.
@Eliaquim It worked! Thank you so much.
Thread closed

Original thread: https://forums.rpgmakerweb.com/threads/mv-error-with-adding-state-via-js.142149/