Help - Item as Variable

Hello!
I want to create a trading system where you can trade x amount of item for a new item.
Example: Trade 5 White Stones, get 1 White Sword.
In case you are wondering, I don't want to do it on a shopping event.
I want to use a regular event.

So maybe it goes like this:

A: Do you want to trade 5 White Stones for a White Sword?
Choices:
Yes
-If White Stone >5
You get White Sword!
Else
You don't have enough White Stone
No

To make that possible, I need to set item quantity as variable.
How to do that?
Can you give me step by step explanations (and some screenshots if you don't mind)?

Thank you in advance!
To get the number of a certain item in the inventory, you use
Code:
$gameParty.numItems(item)
where item refers to an actual item object.
For example:
Code:
// Get number of item with id 1
$gameParty.numItems($dataItems[1])

// Get number of armor with item 1
$gameParty.numItems($dataArmors[1])

// Get number of weapon with id 1
$gameParty.numItems($dataWeapons[1])

To check for a certain number, you can do -> Conditional Branch -> Tab 4 -> Script with
Code:
// Does the party have 5 or more of item with id 1
$gameParty.numItems($dataItems[1]) >= 5

To gain/use an item, you can either use the event commands, or use
Code:
// Take away 5x item with id 1
$gameParty.loseItem($dataItems[1], 5);

// Give the party 10 armors with id 2
$gameParty.gainItem($dataArmors[2], 10);
Or you use Control Variables > Game Data. Don't have to script it.
Wah, it worked perfectly!
Thank you! 😀

Original thread: https://forums.rpgmakerweb.com/threads/help-item-as-variable.86701/