MZ Grab a skill's ID

So...got another potentially stupid question. I have an item object, used for items and skills in battle. How do I get its item ID? I already know how to determine what KIND of object it is(skill or item), but I can't seem to find a method for getting its ID. I hunted down a few functions in the base code that return the id, only for the program to tell me that function isn't a function. Given that I'm replicating how I see the base scripts using it, I can only assume that I've hit another wall where something sounds easy and straightforward, only for it to whack me in the face because me and javascript apparently don't want to get along. Or there's a stupidly simple method that I've not found or overlooked. Trying to follow some of the script flow is like trying to follow a rabbit with a portal gun down an underground maze, so it's entirely possible.

Thanks in advance!
You don't have to backtrack everything through the code (unless you want to for your edification). These engines have been around long enough that most things exist in threads you can find with Google 😉

If you have script that's being executed by the item, you should be able to simply use this.itemId (or variableName.itemId if it's being passed in).

If that doesn't work, post a screenshot of the code you're working with.
You don't have to backtrack everything through the code (unless you want to for your edification). These engines have been around long enough that most things exist in threads you can find with Google 😉

If you have script that's being executed by the item, you should be able to simply use this.itemId

If that doesn't work, post a screenshot of the code you're working with.
The backtracking helps me figure out HOW MZ does what it does. I've learned quite a bit through that.
I've tried searching with Google, that's my go to. Most of the time I find what I'm looking for. When I don't, it's because either people haven't had that issue (either not looking for what I'm looking for or already know how to do it), or they haven't gotten an answer either.
Basically I'm intercepting the item used when the BattleManager executes a skill/item. But it seems like MZ just passes the ball around and never actually needs to reference the id of the object.

JavaScript:
BattleManager.invokeNormalAction = function(subject, target) {
    const realTarget = this.applySubstitute(target);
    this._action.apply(realTarget);
    this._logWindow.displayActionResults(subject, realTarget);
};

This is where I'm grabbing the action from, this._action. I grab it here because I need both the subject and target as well, and this seems the most efficient place to grab it from. Especially since I'd need the realTarget. The _action is a Game_Action, and from what I can find, it has an Item() that returns the actual skill/item being used, and inside that is an itemID(). But the itemID() apparently isn't a function, and everything else returns nothing, essentially like I'm declaring an empty local variable and trying to use it.
itemId is a method defined for Game_Item instances, but the Game_Action#item method skips straight to the database record, i.e. $dataItems or $dataSkills. From there you should be able to reference the id property, e.g.
JavaScript:
action.item().id
Note that the database objects draw directly from files in your project's data subfolder, e.g. check out Skills.json for info on properties available for reference.

I think grabbing the action (and participants) from BattleManager.invokeNormalAction should be OK. If there is a significant delay between fetching the action and referencing it, consider shallow-cloning the action object, e.g. using Object.assign.
The backtracking helps me figure out HOW MZ does what it does.
...and that's exactly what I said, if you're doing it for your own edification 😳
The _action is a Game_Action, and from what I can find, it has an Item() that returns the actual skill/item being used, and inside that is an itemID().
There isn't:

There's just an id property, not itemID (nor itemId). You'd be right at a higher level function that was working from the item in question, but in this case the Game_Action's Item method returns a usableItem, not a Game_Item.
...and that's exactly what I said, if you're doing it for your own edification 😳
In my defense, I was half asleep and had never heard that word before, so I skipped over it. Not every day I learn a new word(was a bookworm as a kid and read parts of the dictionary for fun on occasion), so thanks for expanding my vocabulary!
There's just an id property, not itemID (nor itemId). You'd be right at a higher level function that was working from the item in question, but in this case the Game_Action's Item method returns a usableItem, not a Game_Item.
I had chased it all the way down to the BaseItem, so I think I got a little lost. I'm using Visual Studio Code with LunaLite type definitions for MZ, but sometimes it's not as helpful as I would like. Sometimes it throws another wrinkle in the rabbit chase, and I think that was part of my problem.

I think the actual issue was something else. I was passing my attempts at grabbing the id to a function that displayed the passed value in a message (just to make sure I'm getting what I'm after), it would either be blank or throw an error, depending on what I was trying. The function had another bit in it that did something referencing, but not changing, that value, so I left it.

I decided to console log the value before passing it just now, and it was logging the id with the item().id, but the message was still blank. I removed the extra bit of the function to simplify everything as much as possible, and it started working.

I finally tracked it down, and as usual, it's my experience with another programming language clashing with how javascript works. I had an if statement comparing the passed value to something else. Except in the expression I used "=", not "==", forgetting that in javascript, "=" does NOT do what I expect it to. So instead of referencing, I was overwriting until it BECAME blank. So when the simple method failed, I thought I was not grabbing the id correctly and started chasing the portal rabbit.

I may understand programming at a amateur hobbyist level, but a lot of my specific knowledge is in Visual Basic, and it handles things COMPLETELY differently to javascript with regards to variables, variable types, arrays, and the like. I slip for one second and use what I originally learned, I screw myself over without realizing it.

...I should really use console.log more often. Still not used to having that option available.

Original thread: https://forums.rpgmakerweb.com/threads/grab-a-skills-id.134432/