MV Need help pinpointing issue with my animation plugin

Hey, so I know that there is already a plugin with a similar goal (GALV's Character Frames). But I wanted to make my own to get it how I want it. But I'm kind of stuck. I tried a lot of different methods on transferring the info, and doing it with event tags 'seems' to work.
But the biggest hurdle that I think is stopping things short seems to be the
"Game_CharacterBase.prototype.updatePattern" function.
It never returns the if statement as 'true' so it just returns the else statement.
But idk it could be anything. Honestly at this point I'm just confused. I'm essentially on day 3 of working on this plugin, so my brain is kind of fried. So I figured some fresh eyes would help, especially since y'all are more experienced.
Here's the code.


JavaScript:
/*:
 * @plugindesc Plugin for reading sprites wih more than 3 frames.
 * @author FarawayGoneaway
 */

 ///Hold frame information
  Sprite_Character.prototype.frameSpecs = function () {
    var character = this._character;
    if (character && character.event) {
      var event = character.event();
      var note = event.note;
      var moreFrames = /<MoreFrames:\s*(\d+)\s*(\d+)>/i;
      var match = note.match(moreFrames);
      if (match) {
        var frames = Number(match[1]);
        var frameSize = Number(match[2]);
        return {
          Frames: frames,
          FrameSize: frameSize,
        };
      } else {
        return 3;
      }
    } else {
      return 3;
    }
  };

  Game_CharacterBase.prototype.frameSpecs = function () {
    if (this.event && this.event()) {
      var event = this.event();
      var note = event.note;
      var moreFrames = /<MoreFrames:\s*(\d+)\s*(\d+)>/i;
      var match = note.match(moreFrames);
      if (match) {
        var frames = Number(match[1]);
        return frames;
      } else {
        return 3;
      }
    } else {
      return 3;
    }
  };

  ///Calculate frame size
  var _alias_Sprite_Character_patternWidth =
    Sprite_Character.prototype.patternWidth;
  Sprite_Character.prototype.patternWidth = function () {
    if (this.bitmap && this.bitmap.isReady()) {
      let FrameSpecs = this.frameSpecs();
      if (FrameSpecs && FrameSpecs !== 3) {
        let frameSize = FrameSpecs.FrameSize;
        let calculation = this.bitmap.width / frameSize;
        return calculation;
      } else {
        return _alias_Sprite_Character_patternWidth.call(this);
      }
    } else {
      return _alias_Sprite_Character_patternWidth.call(this);
    }
  };

  var _alias_Sprite_Character_patternHeight =
    Sprite_Character.prototype.patternHeight;
  Sprite_Character.prototype.patternHeight = function () {
    if (this.bitmap && this.bitmap.isReady()) {
      let FrameSpecs = this.frameSpecs();
      if (FrameSpecs && FrameSpecs !== 3) {
        let frameSize = FrameSpecs.FrameSize;
        let calculation = this.bitmap.height / frameSize;
        return calculation;
      } else {
        return _alias_Sprite_Character_patternHeight.call(this);
      }
    } else {
      return _alias_Sprite_Character_patternHeight.call(this);
    }
  };

  var _alias_Sprite_Character_characterPatternX =
    Sprite_Character.prototype.characterPatternX;
  Sprite_Character.prototype.characterPatternX = function () {
    let FrameSpecs = this.frameSpecs();
    if (FrameSpecs && FrameSpecs !== 3) {
      return this._character.pattern();
    } else {
      return _alias_Sprite_Character_characterPatternX.call(this);
    }
  };

  ///Update spritesheet
  var _alias_Game_CharacterBase_updatePattern =
    Game_CharacterBase.prototype.updatePattern;
  Game_CharacterBase.prototype.updatePattern = function () {
    let FrameSpecs = this.frameSpecs();
    if (FrameSpecs && FrameSpecs !== 3) {
      var maxFrames = FrameSpecs;
      this._pattern = (this._pattern + 1) % maxFrames;
    } else {
      return _alias_Game_CharacterBase_updatePattern.call(this);
    }
  };

  var _alias_Sprite_Character_updateCharacterFrame =
    Sprite_Character.prototype.updateCharacterFrame;
  Sprite_Character.prototype.updateCharacterFrame = function () {
    let FrameSpecs = this.frameSpecs();
    if (FrameSpecs && FrameSpecs !== 3) {
      var pw = this.patternWidth();
      var ph = this.patternHeight();
      var sx = (0 + this.characterPatternX()) * pw;
      var sy = (0 + this.characterPatternY()) * ph;
      this.setFrame(sx, sy, pw, ph);
    } else if (FrameSpecs === 3) {
      _alias_Sprite_Character_updateCharacterFrame.call(this);
    }
  };
})();
Hmmm, I only skimmed this (too difficult for me LOL), but what is that .event you're checking? Like in the Sprite_Character frameSpecs doesn't it just return the method for Game_Event [edit: or whatever the character is] (that you're using below)?

EDIT: Oh realized that I guess it's to check that it indeed is an event that has that method, LOL. And probably same for the other point I had in mind for that CharacterBase check.
It never returns the if statement as 'true' so it just returns the else statement.

JavaScript:
  Sprite_Character.prototype.frameSpecs = function () {
    var character = this._character;
    if (character && character.event) {
      ...

  Game_CharacterBase.prototype.frameSpecs = function () {
    if (this.event && this.event()) {
      ...
These if statements which are used to get framespecs in your updatePattern() method are always false because there isn't an event property for the character object.

This means character.event is undefined (makes it false) and this.event is undefined (also false) even though character is true (since it references the actual event object) and this.event() is true (which references the data map event object).

You need to use this condition for the Sprite Charater method:
JavaScript:
if (character instanceof Game_Event) {
   // etc etc
}
And this for the Game_CharacterBase method:
JavaScript:
if (this instanceof Game_Event) {
    // etc etc
}

The operator 'instanceof' compares your object against the constructor (Game_Player, Game_Event, etc.).

This should work assuming the rest of your code works.
These if statements which are used to get framespecs in your updatePattern() method are always false because there isn't an event property for the character object.

This means character.event is undefined (makes it false) and this.event is undefined (also false) even though character is true (since it references the actual event object) and this.event() is true (which references the data map event object).

You need to use this condition for the Sprite Charater method:
JavaScript:
if (character instanceof Game_Event) {
   // etc etc
}
And this for the Game_CharacterBase method:
JavaScript:
if (this instanceof Game_Event) {
    // etc etc
}

The operator 'instanceof' compares your object against the constructor (Game_Player, Game_Event, etc.).

This should work assuming the rest of your code works.
Thank you for that! I need to tinker with it a bit more (namely characterPatternX seems to be the issue now). But you helped the frameSpecs info get through. 😂I used tracers and found that all the functions getting the info are getting it correctly.
Update: I misunderstood and in my tired state, forgot to remove the patternWidth and height functions. So I fixed that, but patternX is still proving to be a problem. I'll keep working but felt I should post an update because I feel dumb for leaving it there lol. But bass's fix was also still necessary


JavaScript:
(function () {
  ///Hold frame information
  Sprite_Character.prototype.frameSpecs = function () {
    var character = this._character;
    if (character instanceof Game_Event) {
      var event = character.event();
      var note = event.note;
      var moreFrames = /<MoreFrames:\s*(\d+)\s*(\d+)>/i;
      var match = note.match(moreFrames);
      if (match) {
        var frames = Number(match[1]);
        var frameSize = Number(match[2]);
        return {
          Frames: frames,
          FrameSize: frameSize,
        };
      } else {
        return 3;
      }
    } else {
      return 3;
    }
  };

  Game_CharacterBase.prototype.frameSpecs = function () {
    if (this instanceof Game_Event) {
      var event = this.event();
      var note = event.note;
      var moreFrames = /<MoreFrames:\s*(\d+)\s*(\d+)>/i;
      var match = note.match(moreFrames);
      if (match) {
        var frames = Number(match[1]);
        return frames;
      } else {
        return 3;
      }
    } else {
      return 3;
    }
  };

  var _alias_Sprite_Character_characterPatternX =
    Sprite_Character.prototype.characterPatternX;
  Sprite_Character.prototype.characterPatternX = function () {
    let FrameSpecs = this.frameSpecs();
    if (FrameSpecs && FrameSpecs !== 3) {
      return this._character.pattern();
    } else {
      return _alias_Sprite_Character_characterPatternX.call(this);
    }
  };

  ///Update spritesheet
  var _alias_Game_CharacterBase_updatePattern =
    Game_CharacterBase.prototype.updatePattern;
  Game_CharacterBase.prototype.updatePattern = function () {
    let FrameSpecs = this.frameSpecs();
    if (FrameSpecs && FrameSpecs !== 3) {
      var maxFrames = FrameSpecs;
        this._pattern = (this._pattern + 1) % maxFrames;
    } else {
      return _alias_Game_CharacterBase_updatePattern.call(this);
    }
  };

  var _alias_Sprite_Character_updateCharacterFrame =
    Sprite_Character.prototype.updateCharacterFrame;
  Sprite_Character.prototype.updateCharacterFrame = function () {
    let FrameSpecs = this.frameSpecs();
    if (FrameSpecs && FrameSpecs !== 3) {
      var pw = FrameSpecs.FrameSize;
      var ph = FrameSpecs.FrameSize;
      var sx = (0 + this.characterPatternX()) * pw;
      var sy = (0 + this.characterPatternY()) * ph;
      this.setFrame(sx, sy, pw, ph);
    } else if (FrameSpecs === 3) {
      _alias_Sprite_Character_updateCharacterFrame.call(this);
    }
  };
})();


Edit for anyone dealing with similar issue: I needed to also modify
"Game_CharacterBase.prototype.pattern" itself because that's what locks 3 in as max and overrode my code.

Original thread: https://forums.rpgmakerweb.com/threads/need-help-pinpointing-issue-with-my-animation-plugin.180052/