[SOLVED] Setting a variable to this.item's id

● ARCHIVED · READ-ONLY
Started by userlame 5 posts View original ↗
  1. I want part of a script to set a variable to the currently selected item's id. I've tried $gameVariables.setValue(2, this.itemId); and all sorts of wacky versions of that. I guesssss I'm misunderstanding something...
  2. The value of "this" depends on when and where you're using that code, because it is a shortcut for the current class/object.
    So you need to show the entire code for help, or replace "this" with the true code for the intended class/object.
  3. I see, well then!
    https://raw.githubusercontent.com/procraftynation/RMV/master/DEX_YEP_ItemDiscard.js
    which is just an addon to https://www.dropbox.com/s/bga5auuxaiwmc4s/YEP_ItemCore.js

    So somewhere within Yanfly's ItemCore is my answer perhaps? But I'm also suspecting the normal item selection when using items works the same, because it tells the game which item to use, and that item has an id associated with it, no?

    I'm trying to add $gameVariables.setValue to the discard action like this
    Code:
    Scene_Item.prototype.onActionDiscard = function () {
        this._itemActionWindow.hide();
        this._itemActionWindow.deactivate();
        SoundManager.playMiss();//TODO PARAM
        $gameVariables.setValue(2, whatdoiputhere);
        $gameParty.loseItem(this.item(), 1, true);
        this.activateItemWindow();
        SceneManager.goto(Scene_Map)
    };
  4. Code:
       $gameVariables.setValue(2, this.item().id);

    How to see where this is coming from?
    1. "this" is dependent on the context. Since it's occuring within the context of Scene_Item, then "this" refers to the instance of Scene_Item
    2. "this.item()" is calling the method "item" of "this". Because we already determined that "this" refers to the instance of Scene_Item, then it's calling the Scene_Item.prototype.item method.
    3. Scene_Item inherits its prototype from Scene_ItemBase.
    4. Search for Scene_ItemBase.prototype.item in the rpg_scenes.js file and you will see that method will return the item that the cursor is currently on in the Item Window
    5. "id" is a property of the item object that is returned.
  5. Awesome informative answer, thx!