MV Calling a function from one plugin to another

To be completely upfront, I am absolutely horrendous at formatting code properly. I do not know the core principles to write it by hand. That being said, I am actually pretty decent at Frankensteining pieces of code together, so I think all I really need help with here is the formatting with how to do this.

What am I trying to accomplish?

I would like to call the BM_EquipCore plugin through my shop plugin as to display the custom equipcore data on the shop scene. I have already done this successfully with other plugins (shop, equip, item, etc), but they were more compatible than the one I am working with now. To do so before, I simply found the proper fields in mjshi's NPCDialogueShop.js and added the commented lines below:

Code:
Window_ShopStatus.prototype.refresh = function() {
    this.contents.clear();
    if (this._item) {
        var x = this.textPadding();
        
        this.drawPossession(x, 0);
        this.drawActorDatakoda();      //koda addition
        if (this.isEquipItem()) {
            this.drawEquipInfo(x, 0);
        }
    }
};

Code:
Window_ShopStatus.prototype.drawActorDatakoda = function() {
    var actor = this.getActor();
//    this.drawActorDisplayed(actor);
    this.drawDarkRectEntries();
    this.drawActorStatInfo(actor);  // leads to YEP_ShopMenuCore which leads to ICFSoft_YEP_ShowParams linked to ICFSuite
    this.drawEquipBody();


This first edit calls a new function, and this new function links to the others. This works because YEP_ShopMenuCore and NPCDialogueShop call from the same parent(?) "Window_ShopStatus"

Now for the current plugin I am working with and trying to incorporate, it uses a slightly different naming convention, 'Window_EquipStatus'.

I think I can get this working by calling (or drawing?) Window_EquipStatus.prototype.refresh, or a similar function from this family found in the BM_EquipCore.js plugin, but I am a bit lost on the correct formatting to do this with.

Specific example of a line I want to try running from the shop base, would be this:

Code:
BM.Equip.Window_EquipStatus_initialize = Window_EquipStatus.prototype.initialize;
Window_EquipStatus.prototype.initialize = function(x, y) {
    this._item = null;
    this._newItem = null;
    var width = this.windowWidth();
    var height = this.windowHeight();
    Window_Base.prototype.initialize.call(this, x, y, width, height);
    this._actor = null;
    this.refresh();
};

So what would be the correct way to format the code, say if I were to put the line under Window_ShopStatus.prototype.refresh = function (in NPCDialogueShop.js), as done in the first two code snippets, but to call (or draw the relevant info boxes provided by) BM.Equip.Window_EquipStatus_initialize instead?

Apologies for the long winded explanation, but I want to make sure my issue is understood clearly. Thank you.


Thinking about this more, is what I am trying to do even possible? Would the data carry over without error even though the function family(?) is different between the two plugins?
To understand where you can use variables, depending on how you define them, you need to understand the concepto of "Scope" in Javascript. Here there is a very good explanation: https://www.w3schools.com/js/js_scope.asp

Window_ShopStatus and Window_EquipStatus are not "naming conventions" but the naming of the prototype. For the sake of simplicity consider the prototype like the definition of a functionality. In Window_ShopStatus you are defining the fucntionality of all related with shopping windows and in Window_EquipStatus with equipment windows

So you are trying to call a window that is rendered when the equip is being shown while you are in the shop. That is key to understand the code and what you are trying

But what I don't get is what do you want to show when? can you share some screenshots of the window you want to replicate and where?
Thank you for the explanation, I have kind of winged code all my life and definitely feel the lack of knowledge affecting my potential.

This is what I have currently, which is a combination of NPCDialogueShop, linked with Yanfly ShopMenuCore, which is then linked with IFCCustomParams + ICFSoft_YEP_ShowParams. The only real change I made here was drawing the sprite (which changes both graphic and shows whether equippable/equipped status and changes which party member is selected with left/right keys), and swapping out the parameter default data with some custom ones. The original version instead compared stats rather than just listing them outright, and only for the main 8 (mhp, mmp, atk, etc)
1701802696663.png



Running this through again, I seem to have made a mistake, as it is actually the item menu that I am looking to modify, as I am actually quite happy with the way the shop screen looks.

So this is what I have currently and what I am actually trying to adjust, thinking the methodologies are likely quite similar. This is from the Integrated Equip System by Mjshi, and as you can see it compares currently equipped items to the item being examined, with the up and down arrows scrolling through the actors one has in their party:

1701803232140.png


What I would like to do, is preferably at its completion, set the left and right, or the pgup and pgdn keys to cycle through which equipment slot is being compared with the item in question. At default it is the main weapon slot, but I want to be able to have the player easily compare the stat difference when equipping a weapon to an offhand or sidearm slot.

The other plugin which I was looking to link to and perhaps piggyback on the code for this, is the BM_EquipCore.js plugin, which changes the equipment scene to the following. As you can see, it allows one to compare weapon slots individually against an equippable item. The left/right or pgup/pgdn solution is the ideal, but isn't really a requirement, just a goal to work towards. Just really looking for a way for the player to easily compare equipment per slot from the item menu (and maybe shop menu too, if I revert back to the parameter comparison window vs the parameter stat table listed directly)

BM_EquipCore.js item comparison screen. I only really am looking to implement the equip screen on the second screenshot and the lefthand table on the first that has Arming Sword -> Chef Knife -> Stat comparisons, and have this capability available for the item and possibly shop scenes.
1701803675917.png


This seems like a lot so I am trying to do this one step at a time. Hopefully I am not out of my league here 😅

edited for clarity
Maybe what you meant is using the JavaScript "window", this creates a global scope function that can be called from other plugins but it's done slightly different from what you said.

if you've a function like this:

JavaScript:
function myFunction () {
    console.log ("This is my plugin function");
}

You can window it this way:
JavaScript:
window.MyPlugin_MyFunction = MyFunction;

(MyPlugin_MyFunction is just a name, you can do as you want just be sure to use a unique function name)

Now you can call MyPlugin_MyFunction from another plugin (given it's below in the list)
That is kind of what I am working towards to get things started, but I don't have any examples on hand to pull the proper formatting of the code from.

If I take this segment here for instance
Code:
Window_ShopStatus.prototype.refresh = function() {
    this.contents.clear();
    if (this._item) {
        var x = this.textPadding();
           
        this.drawPossession(x, 0);
        this.drawActorDatakoda();      //koda addition
        if (this.isEquipItem()) {
            this.drawEquipInfo(x, 0);
        }
    }
};


and I want to have it run the function 'BM.Equip.Window_EquipStatus_initialize'

I would add this somewhere in the above pasted code?

"window.BM.Equip.Window_EquipStatus_initialize = MyFunction;"

I don't think that is correct, but I only have "this." examples to reference, which I believe rely on the current active naming prototype. This is where I get a bit lost.

I see and understand the bit about 'window.MyPlugin_MyFunction = MyFunction;' I think, this is what you put at the top of a new .js file plugin to have it be able to be called. This is definitely helpful but I still don't know how to call it.
Maybe what you meant is using the JavaScript "window", this creates a global scope function that can be called from other plugins but it's done slightly different from what you said.
I don't see that's applicable to what the OP is trying to do.

He wants the display of items in one window to look like they do in a different window. Not the JavaScript browser window, the in-game data types of window.

So you need to copy the appropriate method and name them to overwrite that window type. It has nothing to do with making anything global because then it wouldn't be a method of that data type and nothing would look right.

@Gilgameshed I think the best thing you could do for yourself is to make a post: have one screenshot of what your window looks like now. Either post one other screenshot of what this other window looks like and you describe which elements you want to match; or write, like, two sentences max of clear description. Or, if you have the image editing skills to make a mock up of what you want the UI to look like compared to what it looks like now.

It's just not helpful for you to be posting chunks of code when you admit you don't know what they do, and these posts are so convoluted to try to read through that I feel there has to be a much more efficient approach.
I would like to be able to hit the left or right keys, or the pgup/pgdn keys to change which active equipment slot is being compared in the below screenshot (Integrated Equip System by Mjshi). Having another window pop up which shows which slot is being compared against the weapon/armor piece would also be something I would like to include.

BM_EquipCore.js, which is pictured in the third screenshot of the original post, has functionality similar to this I was considering piggybacking off, but this may not even be needed really.

In the default plugin, when multiple weapons can be equipped, it only compares the stats of the first weapon slot, ignoring any others.

Input.IsTriggered, or just by making a list of specific equip slots and cycling through these seem like the best ways to do this.


----
extra info:
----
This function in Integrated Equip System by Mjshi, seems like a prime candidate for editing or forwarding from. These lines in particular.

var tempActor = JsonEx.makeDeepCopy(actor);
tempActor.forceChangeEquip(this.getSlotID(), this.equip());




Code:
Window_IntegratedEquipMenu.prototype.drawHorzItem = function(index) {
    var rect = this.itemRect(index);
    var actor = $gameParty.battleMembers()[parseInt(this.commandName(index))];
    this.drawCharacter(actor.characterName(),  actor.characterIndex(), paramLeftBuffer/2, rect.y + rect.height/2 + 24);

    var width = (this.itemRect(0).width - paramLeftBuffer) / 8;
    var tempActor = JsonEx.makeDeepCopy(actor);
    tempActor.forceChangeEquip(this.getSlotID(), this.equip());   
    for (var j = 0; j < statsList.length; j++) {
        let i = statsList[j];
        newValue = tempActor.param(i);
        this.changeTextColor(this.paramchangeTextColor(tempActor.param(i) - actor.param(i)));
        this.drawText(tempActor.param(i), paramLeftBuffer + i*width, rect.y + (rect.height - this.lineHeight())/2, width, 'center');
    }
};
You need to learn javascript. I recommend you to take some online courses of vanilla javascript. I don't think is going to be difficult for you because it is clear you are very clever.
But this looks like a couple of hours of work, knowing some javascript basics.
It can be done, definitely

Original thread: https://forums.rpgmakerweb.com/threads/calling-a-function-from-one-plugin-to-another.163604/