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

userlame

Veteran
Veteran
Joined
Nov 25, 2014
Messages
47
Reaction score
9
First Language
English
Primarily Uses
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...
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,365
Reaction score
7,676
First Language
German
Primarily Uses
RMMV
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.
 

userlame

Veteran
Veteran
Joined
Nov 25, 2014
Messages
47
Reaction score
9
First Language
English
Primarily Uses
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)
};
 

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,115
First Language
English
Primarily Uses
RMMV
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.
 

userlame

Veteran
Veteran
Joined
Nov 25, 2014
Messages
47
Reaction score
9
First Language
English
Primarily Uses
Awesome informative answer, thx!
 

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

Latest Threads

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,081
Members
137,582
Latest member
Spartacraft
Top