Yanfly's SelfSwVar plus Moghunter's Chrono compatibility

● ARCHIVED · READ-ONLY
Started by Xenphir 10 posts View original ↗
  1. So I encountered an issue. My game requires ABS battle system and Chrono is the only one I have found that works for me well. However there is an issue using it with Yanfly's SelfSwVar plugin, which I also have to use for complicated event processes.

    The plugins work fine together most of the time, as far as I can tell. The only time an issue comes up is when an enemy in ABS battle dies. I turn off the SelfSwVar plugin and the error doesn't happen, but when I turn it back on, it does. So I know for sure it is this plugin. I have taken damage from enemies and swung at them. Sometimes this error comes up from swinging at the enemy before its HP could reach zero, but it always happens for sure when the enemy dies. The error is screenshot below. It states, "key[2].match is not a function". I'm not sure if it was a key on the keyboard but I can't see anywhere to adjust any sort of key that might have an issue? The attack button is the enter, OK, or Z key. Yanfly's Selfswvar plugin doesn't seem to use keys at all. Unless Key means something else in this case?

    Error
    65166cf8b4ce5afd9c7770302f49428c.png
  2. Screenshot of the console (f8) would be much better than this.
  3. F8 didn't work so I just pressed all the F-buttons and this is what came up. Is this the console?

    Console?
    fcf75edfa20d419f7604b93389c66000.png
  4. Yup, that is console. Can't take a look now, since I'm at work, but it shows the error location.
  5. Poryg said:
    Yup, that is console. Can't take a look now, since I'm at work, but it shows the error location.
    Yeah im not sure how to fix it since I dont understand code but I at least know now that (well im guessing mostly by the words) moghunter uses hidden self variables in their events and its clashing with yanflys directly.
  6. Been awhile so gonna bump this.
  7. Sorry, completely forgot about this. I identified the problem, but fixing it would require to rework the entire plugin. The reason is, MOG tries to use the self switches standard MV engine way. Yanfly has introduced her own formatting to the self switches.
  8. Poryg said:
    Sorry, completely forgot about this. I identified the problem, but fixing it would require to rework the entire plugin. The reason is, MOG tries to use the self switches standard MV engine way. Yanfly has introduced her own formatting to the self switches.
    ah okay thanks. Is there a way to turn plugins off and on mid-game via a switch? If so I could simply not use any events that require her self-switch/variables in battle-areas for now, until I can afford my own plugin.
  9. There is no native way to unload a plugin via a switch. The reason is, upon adding as a script element, the parser will parse through all functions in the plugin and define them. There's no way to unparse a function or revert it to previous change except via a redefinition. However, in order to redefine a function you need to operate on a top level.
    So that means there is pretty much only one workaround.
    Having a .js file inside the game js/plugins folder. It would contain this code:
    Code:
    Game_SelfSwitches.prototype.value = Yanfly.SSV.Game_SelfSwitches_value;
    Game_SelfSwitches.prototype.setValue = Yanfly.SSV.Game_SelfSwitches_setValue;
    Game_SelfSwitches.prototype.onChange = Yanfly.SSV.Game_SelfSwitches_setValue;
    in other words it contains code to revert Yanfly's changes.

    Then you'd have another file, which contains these functions:
    Code:
    Yanfly.SSV.Game_SelfSwitches_value = Game_SelfSwitches.prototype.value;
    Game_SelfSwitches.prototype.value = function(key) {
      if (key[2].match(/SELF[ ]VAR/i)) {
        this._data[key] = this._data[key] || 0;
        return this._data[key];
      }
      return Yanfly.SSV.Game_SelfSwitches_value.call(this, key);
    };
    
    Yanfly.SSV.Game_SelfSwitches_setValue = Game_SelfSwitches.prototype.setValue;
    Game_SelfSwitches.prototype.setValue = function(key, value) {
      if (key[2].match(/SELF[ ]VAR/i)) {
        this._data[key] = value;
        this.onChange();
      } else {
        Yanfly.SSV.Game_SelfSwitches_setValue.call(this, key, value)
      }
    };
    
    Yanfly.SSV.Game_SelfSwitches_onChange = Game_SelfSwitches.prototype.onChange;
    Game_SelfSwitches.prototype.onChange = function() {
      Yanfly.SSV.Game_SelfSwitches_onChange.call(this);
      if ($gameTemp.getSelfSwVarEventOneTimeClear()) {
        $gameTemp.setSelfSwVarEventOneTimeClear(false);
        $gameTemp.clearSelfSwVarEvent();
      }
    };
    In other words it implements Yanfly's changes back.

    Then you'd have a plugin file that loads whatever plugin is necessary on demand. I'm including the base of this plugin in this reply, however since I have absolutely no idea when you use self switches, I don't know where should I even plant the functions necessary to call. So I kind of hope you figure that out :D
    Btw. using these functions it would be possible to make it possible to load/unload the plugin via switch.
  10. Since MOG's Chrono Engine uses self switches for determining if the player is close enough (via Event Sensor Plugin) and when the event is dead (via Chrono Engine Plugin), how would I implement the code you gave?