Bizarre Global State Behavior

● ARCHIVED · READ-ONLY
Started by EricW 4 posts View original ↗
  1. Hi,
    I'm using Yanfly's AutoPassiveStates and Buffs + States Core Plugins to try and give my actors dynamic action times+ values using states.

    However, for whatever reason the game really *really* doesn't like what i'm trying to do and the bolded part of code is terribly bugged.

    Note: The actor passive state id is 73
    <Custom Battle Effect>
    var Q1 = 80;
    if (!this.isStateAffected(Q1)){
    this.addState(Q1);
    }
    </Custom Battle Effect>

    <Custom Turn End Effect>
    var Q1 = 80;
    var Q2 = 78;
    var Q3 = 76;
    var Q4 = 74;

    if (user.isStateAffected(Q1)){
    this.removeState(Q1);
    this.addState(Q2);
    }
    else if (this.isStateAffected(Q2)){
    this.removeState(Q2);
    this.addState(Q3);
    }
    else if (this.isStateAffected(Q3)){
    this.removeState(Q3);
    this.addState(Q4);
    }
    </Custom Turn End Effect>

    <Custom Action Start Effect>
    var Q1 = 80;
    var Q2 = 78;
    var Q3 = 76;
    var Q4 = 74;
    var action = this.currentAction();
    var skill = action.item();
    // Check if the action exists, is a skill
    if (action && action.isSkill()) {
    if(!this.isInstantCast(skill)){
    if (this.isStateAffected(Q2)){
    this.addState(Q1);
    this.removeState(Q2);
    }
    if (this.isStateAffected(Q3)){
    this.addState(Q2);
    this.removeState(Q3);
    }
    if (this.isStateAffected(Q4)){
    this.addState(Q3);
    this.removeState(Q4);
    }

    }
    }
    </Custom Action Start Effect>

    What happens is --the state will get removed and the new state will not be added back.
    The bolded code works if the state getting added has *any other state* other than states Q1- Q4 (e.g. states 01-72).
    It's absolutely baffling. Is there something i'm overlooking?
    Pictures of the states are below:
    upload_2018-10-13_16-43-30.png

    upload_2018-10-13_16-43-41.png

    upload_2018-10-13_16-43-54.png

    upload_2018-10-13_16-44-6.png
  2. if (action && action.isSkill()) {
    if(!this.isInstantCast(skill)){
    if (this.isStateAffected(Q2)){
    this.removeState(Q2);
    console.log(1);
    while (!this.isStateAffected(Q1)){
    console.log(2);
    this.addState(Q1);
    }

    I must be doing something very wrong because printing to console just confirmed that rpg maker would rather infinitely loop than add state Queue 1 to my battler.
  3. This has been solved. The states need to be replaced on action end instead of action start.

    An example is
    <Custom Action End Effect>

    var action = this.currentAction();

    var skill = action.item();

    if(!user.isInstantCast(skill)){

    user.addState(76);

    user.removeState(74);

    }

    </Custom Action End Effect>

    I suspect this is due to the states dealing with action times+
  4. Just so you have a better understanding of why it wasn't working in the first place:

    EricW said:
    if (this.isStateAffected(Q2)){
    this.addState(Q1);
    this.removeState(Q2);
    }
    if (this.isStateAffected(Q3)){
    this.addState(Q2);
    this.removeState(Q3);
    }
    if (this.isStateAffected(Q4)){
    this.addState(Q3);
    this.removeState(Q4);
    }

    The keyword "this" has a special meaning in Javascript and is dependent on the context that a function is evaluated in. "isStateAffected" is a method available to check if an actor has a state, and it has to be called in the context of an actor. However, the notetag <Custom Action Start Effect> is evaluated in the context of a Game_Action, so the "this" keyword refers to the action not the actor.

    EricW said:
    if (action && action.isSkill()) {
    if(!this.isInstantCast(skill)){
    if (this.isStateAffected(Q2)){
    this.removeState(Q2);
    console.log(1);
    while (!this.isStateAffected(Q1)){
    console.log(2);
    this.addState(Q1);
    }

    Same thing here. "this" is evaluated in the context of the action and not the actor, therefore "this.isStateAffected" and "this.addState" aren't valid. Those would have to be called in the context of the actor/user, which is why it works when you changed "this" to "user".