MV Need Help Referencing A Selected Item

I'm using Yanfly's Equip Customize, Item Core, and Attach Augments plugins to make a tooltip script when equipping/unequipping items to a piece of armor. I've made modifications to the Equip Customize script and my specific modifications are posted below. I also have another script that displays a window whenever the item scene is accessed within this custom scene from the equip customize script.

Spoiler: Custom Code in the Equip Customize Script
JavaScript:
function Scene_EquipArmaments() {
    this.initialize.apply(this, arguments);
}

Scene_EquipArmaments.prototype = Object.create(Scene_Item.prototype);
Scene_EquipArmaments.prototype.constructor = Scene_EquipArmaments;

Scene_EquipArmaments.prototype.initialize = function() {
    Scene_Item.prototype.initialize.call(this);
};

Scene_EquipArmaments.prototype.createCategoryWindow = function() {
    Scene_Item.prototype.createCategoryWindow.call(this);
    this._categoryWindow.deactivate();
    this._categoryWindow.hide();
    var wy = this._helpWindow.height;
    this._commandWindow = new Window_EquipCommand(0, -300, 240);
    this.addWindow(this._commandWindow);
    this._commandWindow.deactivate();
    var index = this._commandWindow.findSymbol('customize');
    this._commandWindow.select(index);
};

Scene_EquipArmaments.prototype.item = function() {
    return $gameTemp._customizeItem;
};


Scene_EquipArmaments.prototype.createItemWindow = function() {
    Scene_Item.prototype.createItemWindow.call(this);
    this._itemWindow._data = [$gameTemp._customizeItem];
    this._itemWindow.select(1);
    this._itemWindow.hide();
   
};

Scene_EquipArmaments.prototype.createActionWindow2 = function() {
    Scene_Item.prototype.createActionWindow2.call(this);
    this.setCustomizedItem();
   
};

Scene_EquipArmaments.prototype.setCustomizedItem = function() {
   this._helpWindow.setItem(this.item());
    this._statusWindow.setItem(this.item());
    this._infoWindow.setItem(this.item());
    this._itemActionWindow.setItem(this.item());
    if ($gameTemp._itemActionIndex) {
      this._itemActionWindow.select($gameTemp._itemActionIndex);
    }
};

 Scene_EquipArmaments.prototype.createCardDescriptions = function() {
    Scene_Item.prototype.createCardDescriptions.call(this);
};

Scene_EquipArmaments.prototype.onActionCancel = function() {
    $gameTemp._customizeItem = null;
    $gameTemp._customizeReturning = true;
    $gameTemp._equipCustomize = false;
    SceneManager.pop();
};

Scene_EquipArmaments.prototype.onUpgradeFullReset = function() {
    ItemManager._fullReset = false;
    this.onActionCancel();
};
Spoiler: My own Custom Window Script
JavaScript:
function Window_CardDescriptions() {
    this.initialize.apply(this, arguments);
}

Window_CardDescriptions.prototype = Object.create(Window_Base.prototype);
Window_CardDescriptions.prototype.constructor = Window_CardDescriptions;

Window_CardDescriptions.prototype.initialize = function(x, y, width, height) {
    Window_Base.prototype.initialize.call(this, x, y, width, height);

    this._lastItem = null; // Track the last selected item
};

Window_CardDescriptions.prototype.update = function() {
    Window_Base.prototype.update.call(this);
this.opacity = 255;
var equipScene = SceneManager._scene; // Reference to the equip scene
var itemWindow = equipScene._itemWindow; // Reference to the item window in the equip scene
var selectedItem = itemWindow.item(); // Retrieve the selected item


    if (this._lastItem !== selectedItem) {
        this._lastItem = selectedItem;
        this.refresh();
    }
};

Window_CardDescriptions.prototype.refresh = function() {
    this.contents.clear();
var equipScene = SceneManager._scene; // Reference to the equip scene
var itemWindow = equipScene._itemWindow; // Reference to the item window in the equip scene
var selectedItem = itemWindow.item(); // Retrieve the selected item
console.log(selectedItem); // Output the selected item to the console

// Check if the item exists and its ID is 101
    if (selectedItem && selectedItem.id === 101) {
        // Draw weapon-specific content
        this.drawText("Avalo", 0, 0, this.contents.width, "center");
    } else if (selectedItem && selectedItem.id === 102) {
        // Draw weapon-specific content
        this.drawText("Avaega", 0, 0, this.contents.width, "center");
    } else if (selectedItem && selectedItem.id === 103) {
        // Draw weapon-specific content
        this.drawText("Avagigos", 0, 0, this.contents.width, "center");
    } else if (selectedItem && selectedItem.id === 104) {
        // Draw weapon-specific content
        this.drawText("Vyrkalo", 0, 0, this.contents.width, "center");
    } else if (selectedItem && DataManager.isArmor(selectedItem)) {
        // Draw armor-specific content
        this.drawText("This is an armor.", 0, 0, this.contents.width, "center");
    } else {
        // Draw default content
        this.drawText("No item selected.", 0, 0, this.contents.width, "center");
    }
};

The image below is a screenshot of the custom equip customize scene. It functions and behaves like the script normally would by default. What I want is for the window on the right to display information based on what is highlighted in the screenshot and for it to be updated in real-time whenever I scroll up and down through the items. I would also like for it to display the same information whenever I'm scrolling up and down the list of equippable items through the Attach Augments script. I can't imagine it being much more than 2 or 3 lines of code.
Menu Reference.png
Haven't you already done that in your code?
JavaScript:
var selectedItem = itemWindow.item(); // Retrieve the selected item

All the information about your selected item should be contained in this object, shouldn't it?

By default, a database consumable item should have the following properties attached to their object (the below example comes from item 1 Potion on a blank project):
Code:
animationId: 41
consumable: true
damage: {critical: false, elementId: 0, formula: '0', type: 0, variance: 20}
description: ""
effects: [{…}]
hitType: 0
iconIndex: 176
id: 1
itypeId: 1
meta: {}
name: "Potion"
note: ""
occasion: 0
price: 50
repeats: 1
scope: 7
speed: 0
successRate: 100
tpGain: 0
This corresponds to the data fields in the database entry for the item. Depending on those plugins you are using, this list may have some extra stuff on it, I don't know what Yanfly may or may not have added to the usual item properties, you'll have to check yourself.

You're already referencing the item ID in your code, when you check "selectedItem.id". You can do the same with the other properties the same way like "selectedItem.name" or "selectedItem.price".

Then all you need to do is use those values in your function calls, like:
Code:
this.drawText(selectedItem.name, 0, 0, this.contents.width, "center");
Haven't you already done that in your code?
JavaScript:
var selectedItem = itemWindow.item(); // Retrieve the selected item

All the information about your selected item should be contained in this object, shouldn't it?

By default, a database consumable item should have the following properties attached to their object (the below example comes from item 1 Potion on a blank project):

This corresponds to the data fields in the database entry for the item. Depending on those plugins you are using, this list may have some extra stuff on it, I don't know what Yanfly may or may not have added to the usual item properties, you'll have to check yourself.

You're already referencing the item ID in your code, when you check "selectedItem.id". You can do the same with the other properties the same way like "selectedItem.name" or "selectedItem.price".

Then all you need to do is use those values in your function calls, like:
Code:
this.drawText(selectedItem.name, 0, 0, this.contents.width, "center");
Well, under augmentSlotItems in the console gives me a list of everything that's equipped onto the base item. I have no idea how to reference the attached item's id and have it change/update the custom window script based on what is currently highlighted. btw thank you for replying.
Well, under augmentSlotItems in the console gives me a list of everything that's equipped onto the base item. I have no idea how to reference the attached item's id and have it change/update the custom window script based on what is currently highlighted. btw thank you for replying.
That's not a default item property, it's added to the item by Yanfly's plugin. To see how it works, you should take a look at how the Attach Augments plugin handles it within itself.

From my understanding, the values that are stored within each index of the "augmentSlotItems" array contain the IDs of the attachments. They appear to be stored as a string taking the format "itemtype X" where item type is either a consumable, weapon or armor as in the database tabs (either 'item X', 'weapon X' or 'armor X') and X is its ID within the database.

By default, the engine loads consumables, weapon and armor data from the database into the variables $dataItems, $dataWeapons and $dataArmor respectively.

Yanfly's plugin appears to chop up this string when it needs to identify which database item is meant to be the augment in question.

You should take a look at the function called "ItemManager.augmentInSlot()" in Yanfly's plugin. This function is the one that chops up the string and looks up the ID in $dataItems/$dataWeapons/$dataArmors.

In fact, I believe that function itself does exactly what you want to do - given an item object and an augment slot ID, it retrieves the augment item from that slot and returns it.

(Though it honestly wouldn't be hard to write your own parsing function if you wanted to do that too, you can just split the string on the whitespace.)
That's not a default item property, it's added to the item by Yanfly's plugin. To see how it works, you should take a look at how the Attach Augments plugin handles it within itself.

From my understanding, the values that are stored within each index of the "augmentSlotItems" array contain the IDs of the attachments. They appear to be stored as a string taking the format "itemtype X" where item type is either a consumable, weapon or armor as in the database tabs (either 'item X', 'weapon X' or 'armor X') and X is its ID within the database.

By default, the engine loads consumables, weapon and armor data from the database into the variables $dataItems, $dataWeapons and $dataArmor respectively.

Yanfly's plugin appears to chop up this string when it needs to identify which database item is meant to be the augment in question.

You should take a look at the function called "ItemManager.augmentInSlot()" in Yanfly's plugin. This function is the one that chops up the string and looks up the ID in $dataItems/$dataWeapons/$dataArmors.

In fact, I believe that function itself does exactly what you want to do - given an item object and an augment slot ID, it retrieves the augment item from that slot and returns it.

(Though it honestly wouldn't be hard to write your own parsing function if you wanted to do that too, you can just split the string on the whitespace.)
Sorry for such a late response but I'm not quite acquainted enough with coding to write a solution out on my own. Could you provide me with an example?
Sorry for such a late response but I'm not quite acquainted enough with coding to write a solution out on my own. Could you provide me with an example?

Like I said, if you want to reference the attached augment item data, you can just use the "augmentInSlot()" function that Yanfly had in his plugin. You don't need to write your own code to parse the string, Yanfly already provided a function to retrieve the augment data, it's "ItemManager.augmentInSlot()".

Your custom window script retrieves the item in this line:
JavaScript:
var selectedItem = itemWindow.item(); // Retrieve the selected item
So for example, if you want to access the augment attached to the first slot, you just use:
JavaScript:
ItemManager.augmentInSlot(selectedItem, 0);
That will give you the exact database Item (or Weapon or Armor if your augment was a weapon/armor) object that the augment came from, containing all the data from the database, including the ID.

From there, you can pull out whatever information you need and draw it onto the screen.
Like I said, if you want to reference the attached augment item data, you can just use the "augmentInSlot()" function that Yanfly had in his plugin. You don't need to write your own code to parse the string, Yanfly already provided a function to retrieve the augment data, it's "ItemManager.augmentInSlot()".

Your custom window script retrieves the item in this line:
JavaScript:
var selectedItem = itemWindow.item(); // Retrieve the selected item
So for example, if you want to access the augment attached to the first slot, you just use:
JavaScript:
ItemManager.augmentInSlot(selectedItem, 0);
That will give you the exact database Item (or Weapon or Armor if your augment was a weapon/armor) object that the augment came from, containing all the data from the database, including the ID.

From there, you can pull out whatever information you need and draw it onto the screen.
JavaScript:
var equipScene = SceneManager._scene; // Reference to the equip scene
var itemWindow = equipScene._itemWindow; // Reference to the item window in the equip scene
var selectedItem = itemWindow.item(); // Retrieve the selected item

Hmm, maybe my custom script in the line above isn't right because it keeps referencing just one item constantly, no matter where I move the cursor.
Hmm, maybe my custom script in the line above isn't right because it keeps referencing just one item constantly, no matter where I move the cursor.
In that case, you will need to take a look at the item window you're grabbing the item from and make sure it's actually working properly and also that your scene is updating your custom window along with the others.

I'm afraid I can't really help you beyond that, as I have no clue what changes you have made to the default classes (although I can tell you have made them, since you call some custom function named "createCardDescriptions()" on Scene_Item that does not exist in the default codebase).

(And I don't know what changes any of the external plugins you have installed may have made to them either.)

Original thread: https://forums.rpgmakerweb.com/threads/need-help-referencing-a-selected-item.157629/