Script for number of 1 item

I was looking into a conditional branch for if the player has more then 1 of an item. I was doing a loooooong if check (see below) to do this. But it got tiresome so I started researching and came across this post (Click here).
Capture.PNG

(A long list of if conditions inside other if conditions)

In the link above there's a script:
$game_party.item_number($data_items[n]) >= 10
{^This script is for VX Ace | Didn't notice Sorry}

I tried this for a clay required mission:
Player needs 3 clay for event to turn on self switch a
but I couldn't get it to work.

Here's the item in question:
Capture.PNG

(1971 Clay)
I tried the script:
$game_party.item_number($data_items[1971]) >= 3
and
$game_party.item_number($data_items[1971 Clay]) >= 3

Sadly they both failed to work. What am I doing wrong?

More Screen Shots!
Capture.PNG

(Player Inventory Empty)

Capture.PNG

(Player received Clay item)

Capture.PNG

(Player has 3 Clay in their inventory)

Capture.PNG

(Script does not see that the player has 3 Clay in their inventory)

tl;dr: How do we use the script here for the inventory amount check?
👋 The script you're trying is for VX Ace, that's why it's not working.

However, you can do this without scripting:
  • To get the number of a specific item, use Control Variables > Game Data > Item;
  • You can then use Conditional Branch > Variable to check the value against a threshold.
Spoiler: Click to see an event example
Code:
◆Control Variables:#0007 Count = The number of Potion
◆If:Count ≥ 5
  ◆Text:None, Window, Bottom
  :    :Yay, you have 5 Potions!
  ◆
:Else
  ◆Text:None, Window, Bottom
  :    :I need 5 Potions for the Ultra Potion.
  :    :You have \v[7] Potions right now.
  ◆
:End

The script equivalent would be something like this (Conditional Branch > Script):
JavaScript:
$gameParty.numItems($dataItems[1]) >= 5
I.e. "return true iff the party has 5 or more of item ID 1". Replace $dataItems with $dataWeapons or $dataArmors if you want to check a weapon or armor instead.

Note that it's often useful to have the number stored in a variable for easy reference in Show Text, as demonstrated in my event example. 🙏
👋 The script you're trying is for VX Ace, that's why it's not working.

However, you can do this without scripting:
  • To get the number of a specific item, use Control Variables > Game Data > Item;
  • You can then use Conditional Branch > Variable to check the value against a threshold.
Spoiler: Click to see an event example
Code:
◆Control Variables:#0007 Count = The number of Potion[/INDENT]
[INDENT]◆If:Count ≥ 5[/INDENT]
[INDENT]  ◆Text:None, Window, Bottom[/INDENT]
[INDENT]  :    :Yay, you have 5 Potions![/INDENT]
[INDENT]  ◆[/INDENT]
[INDENT]:Else[/INDENT]
[INDENT]  ◆Text:None, Window, Bottom[/INDENT]
[INDENT]  :    :I need 5 Potions for the Ultra Potion.[/INDENT]
[INDENT]  :    :You have \v[7] Potions right now.[/INDENT]
[INDENT]  ◆[/INDENT]
[INDENT]:End

The script equivalent would be something like this (Conditional Branch > Script):
JavaScript:
$gameParty.numItems($dataItems[1]) >= 5
I.e. "return true iff the party has 5 or more of item ID 1". Replace $dataItems with $dataWeapons or $dataArmors if you want to check a weapon or armor instead.

Note that it's often useful to have the number stored in a variable for easy reference in Show Text, as demonstrated in my event example. 🙏



I think I already do this with some items.
Capture.PNG

(Remove wood from inventory + Change Wood Count Variable -= 1)

And when the player cuts a tree:
Capture.PNG

(Add wood to inventory + Change Wood Count Variable += 1)

So for script I can write:
$gameParty.numItems($dataItems[2]) >= 2

instead of:
Capture.PNG

(If Wood Count >= 2
Change Items : Wood - 2
Control Variables : #0002 Wood Count -= 2)
I think I already do this with some items.
no, what you're doing has nothing to do with game data
your screenshots show manual counting.

game data is automatic counting and replaces the script you're looking for.

using game data means to load the number of items from inventory into the variable, no matter what that number is and without using any other command.

in fact your example is a poor use of control variable and shows how NOT to do it.

please open your project, go to any event and add a control variable command to it.
then select game data, and change the default "map ID" by clicking into that line.
and then wonder how much you can do with the control variable command in the next window....

EDIT:
here is a screenshot of what you need:
number of.png
please open your project, go to any event and add a control variable command to it.
then select game data, and change the default "map ID" by clicking into that line.
and then wonder how much you can do with the control variable command in the next window....

GAME CHANGER ! THANK YOU SO MUCH !
please open your project, go to any event and add a control variable command to it.
then select game data, and change the default "map ID" by clicking into that line.
and then wonder how much you can do with the control variable command in the next window....

I think I kind of understand the core concept.

Did I get it right?

Capture.PNG

Choice (Fix Chair, X)
When Fix Chair
->Control Variable : (The variable that is to be set to the item quantity)
I used the variable Wood Count for consistency - but if I'm not mistaken it would be better to have a variable like "Check Item Amount", as this will constantly change for when ever an item is needed.
->if (Variable) >= (Amount needed)
Change item : (Item checked & used) - (Amount Needed)

->else
(Message of not meeting required item count | You don't have enough of item X)


Is the core logic mentioned above the right way to think about it?
yes, that is the basic principle

Original thread: https://forums.rpgmakerweb.com/threads/script-for-number-of-1-item.131369/