Get Item ID from it's name

Hello!
I was wondering, if there is a way to get the ID of an item from its name? (as a script call)
Iam using GALVs simple Crops and when harvesting the crop the scriptcall stores the name of the
item in a variable. But I would need the ID of that item. So maybe there is a scriptcall to check the name of the Item and store its Item ID in another variable?

Galvs ScriptCall to get name of Item:

Code:
// Get item and store item name in variable
Galv.CROPS.harvest(this._eventId,211);

Galvs Script
So maybe there is a scriptcall to check the name of the Item and store its Item ID in another variable?
if its a a standard game variable that its storing the item in, youd just use $gameVariables.value(x).id to get the id of the item
if its a a standard game variable that its storing the item in, youd just use $gameVariables.value(x).id to get the id of the item
I am not sure if its will work, because it stores a text (string?) in variable 211. So its realy just a text with the name of the item. And I would need a script call, which checks the text in 211, finds the ID of the item with this name and stores it in another variable 212
Code:
const itemName = $gameVariables.value(211);
const item = $dataItems.filter(Boolean).find(item => item.name == name);
const itemId = item ? item.id : 0;
$gameVariables.setValue(212, itemId);

This is not a plugin. You need to call this code via script, and then it will put the ID into variable 212.
I am not sure if its will work, because it stores a text (string?) in variable 211. So its realy just a text with the name of the item.
completely missed the part where you said its the name it stores, but Aerosys has it sorted
Code:
const itemName = $gameVariables.value(211);
const item = $dataItems.filter(Boolean).find(item => item.name == name);
const itemId = item ? item.id : 0;
$gameVariables.setValue(212, itemId);
This is not a plugin. You need to call this code via script, and then it will put the ID into variable 212.
I'm a bit lost here as ItemName is never defined unless `name` = itemName
but Boolean is also a variable unless it's used differently in filters?
@ShadowDragon - Boolean is a constructor function. @Aerosys is using it to exclude item ID 0 (null), because the only falsy number is 0 [edit: rather, because null is falsy but objects are not].

@ChershireHatter - I'd suggest this instead, to avoid an extra loop and excess object creation:
JavaScript:
var name = $gameVariables.value(211);
var itemId = 0;
for (var n = $dataItems.length; --n;) {
  if ($dataItems[n].name === name) {
    itemId = $dataItems[n].id;
    break;
  }
}
$gameVariables.setValue(212, itemId);
If you happen to be using Yanfly's independent items from YEP Item Core then you may want to replace .id with .baseItemId.
I'm a bit lost here as ItemName is never defined unless `name` = itemName
but Boolean is also a variable unless it's used differently in filters?
list.filter(Boolean) is just a shorthand for list.filter(item => item is nor null, undefined, or 0)
@ShadowDragon - Boolean is a constructor function. @Aerosys is using it to exclude item ID 0 (null), because the only falsy number is 0.

@ChershireHatter - I'd suggest this instead, to avoid an extra loop and excess object creation:
JavaScript:
var name = $gameVariables.value(211);
var itemId = 0;
for (var n = $dataItems.length; --n;) {
  if ($dataItems[n].name === name) {
    itemId = $dataItems[n].id;
    break;
  }
}
$gameVariables.setValue(212, itemId);
If you happen to be using Yanfly's independent items from YEP Item Core then you may want to replace .id with .baseItemId.

This one worked great! <3 Thank you!
The one from @Aerosys also did something, but seem to get 0 so it picked the first empty item slot. don't know why, but caethyrils code just worked perfect!

Thank you all for your help! <3

​

Original thread: https://forums.rpgmakerweb.com/threads/get-item-id-from-its-name.170690/