Trouble aliasing a function from Yanfly Keyboard Config

Ritter

Veteran
Veteran
Joined
Jan 17, 2017
Messages
60
Reaction score
27
First Language
English
Primarily Uses
RMMV
I'm trying to alias a function from Yanfly Keyboard Config within a plugin I've created. What I want to do is make my code run after this function runs but if I so much as alias the function it messes up the function and it doesn't run at all. Maybe I'm doing something wrong?
I was able to successfully alias another function within the plugin and add the keys to the list of actions when you select a button to bind it but this one keeps giving me problems.

This is what I'm trying to do, this function is called to determine what text shows up on the keys if they are in use. I would like my parameters to show up as the name that gets drawn on the keys.

This code below will make the text show up on the keys but ONLY these keys and not every other key that is normally drawn using the original function in Yanfly Keyboard config.

JavaScript:
    var Ritter_Window_KeyConfig = Window_KeyConfig.prototype.actionKey;
    Window_KeyConfig.prototype.actionKey = function(action) {
        Ritter_Window_KeyConfig.call(this,action);
        switch(action) {
            case Ritter.Params.togForButton[1]:
                return Ritter.Params.togForName;
                break;
            case Ritter.Params.togBackButton[1]:
                return Ritter.Params.togBackName;
                break;
            case Ritter.Params.useItemButton[1]:
                return Ritter.Params.useItemName;
                break;
        }
    };
If i do this below then no text will be drawn on any keys.

JavaScript:
    var Ritter_Window_KeyConfig = Window_KeyConfig.prototype.actionKey;
    Window_KeyConfig.prototype.actionKey = function(action) {
        Ritter_Window_KeyConfig.call(this,action);
    };
Hoping someone can help me figure out what it is I'm doing wrong here. :mrsatan:
 

standardplayer

Keeper of Kitties
Veteran
Joined
Apr 6, 2016
Messages
621
Reaction score
2,780
First Language
English
Primarily Uses
N/A
Was the aliased function originally returning a value, when it was finished?
If so, it currently isn't returning anything, so that could be an issue. I don't have these plugins at hand to review, unfortunately

If this is the case, then when you call the aliased function, assign it's result to a variable.
Then at the end of your process that you added, return that value before the function closes.
 

Ritter

Veteran
Veteran
Joined
Jan 17, 2017
Messages
60
Reaction score
27
First Language
English
Primarily Uses
RMMV
As this plugin is one of yanflys free downloads I suppose posting the original function shouldn't hurt anything. It returns many values depending on the key which it is accessing. I was hoping to be able to return my own data after it writes the text for every button. The top code I posted does draw the text as I want it to on the proper keys but I just need it to also draw the text for every other button :D

JavaScript:
Window_KeyConfig.prototype.actionKey = function(action) {
        switch(action) {
        case 'ok':
            return Yanfly.Param.KeyConfigOkKey;
            break;
        case 'escape':
            return Yanfly.Param.KeyConfigEscKey;
            break;
        case 'cancel':
            return Yanfly.Param.KeyConfigCancelKey;
            break;
        case 'menu':
            return Yanfly.Param.KeyConfigMenuKey;
            break;
        case 'shift':
            return Yanfly.Param.KeyConfigShiftKey;
            break;
        case 'pageup':
            return Yanfly.Param.KeyConfigPageUpKey;
            break;
        case 'pagedown':
            return Yanfly.Param.KeyConfigPageDnKey;
            break;
        case 'left':
            return Yanfly.Param.KeyConfigLeftKey;
            break;
        case 'up':
            return Yanfly.Param.KeyConfigUpKey;
            break;
        case 'right':
            return Yanfly.Param.KeyConfigRightKey;
            break;
        case 'down':
            return Yanfly.Param.KeyConfigDownKey;
            break;
    default:
      if (Imported.YEP_ButtonCommonEvents) {
        if (Yanfly.Param.BCEList[action]) {
          var id = Yanfly.Param.BCEList[action];
          var ev = $dataCommonEvents[id];
          return ev.configKey;
        }
      }
      return '';
      break;
        }
};
Edit:

So I just tried this and it seems to work, I'm not sure if this is proper though. Thanks for posting, it really helped clear up what was happening here, things just weren't clicking in my brain. :mrsatan:

JavaScript:
    var Ritter_Window_KeyConfig = Window_KeyConfig.prototype.actionKey;
    Window_KeyConfig.prototype.actionKey = function(action) {
       
        switch(action) {
            case Ritter.Params.togForButton[1]:
                return Ritter.Params.togForName;
                break;
            case Ritter.Params.togBackButton[1]:
                return Ritter.Params.togBackName;
                break;
            case Ritter.Params.useItemButton[1]:
                return Ritter.Params.useItemName;
                break;
            default:
                return Ritter_Window_KeyConfig.call(this,action);
                break;
        }
    };
 
Last edited:

standardplayer

Keeper of Kitties
Veteran
Joined
Apr 6, 2016
Messages
621
Reaction score
2,780
First Language
English
Primarily Uses
N/A
It's fine to do it this way, you don't actually need the break statements now, though, bc whenever it reaches a return statement, the function exits. But outside of that yeah, it looks like the rest of the program wasn't getting that returned value it was expecting.

I've done that a bunch of times; aliased something and 'broke' everything, only to find that it was just the original returned value missing :b
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Vote for what I show more indepth on Twitter tomorrow from the MZ default resources
Oh look, 12 more free Daz3D models. *adds them to his collection * Yes, the fools... Give it a few months and my collection will be crazy, all without paying a dime. I still have no idea if I'll ever learn the software, but hey... Just in case, these models are quite expensive. In two weeks, they've already given me almost $400 worth of free models. :LZSexcite:
Not easy to find DS resources, is it? I need to make a good compilation thread linking to all the artists that do DS...
Spent a whole evening planning Stats, Animations, Abilities of 24 different weapons.. Only to realize I was just Bloating the Game. In the end i decided to stick with only 6.
Haven’t gotten over a mentor’s promotion. He deserves it, but he was the first person to be nice to me at work. It’s been hard for me to let him go.

Forum statistics

Threads
99,351
Messages
964,364
Members
130,948
Latest member
saltfilter
Top