Gaining/Losing Item Script Call Help

Hello.

I am trying to force the player to enter battle with a limited number of items.

1) I use the Select Item command and then the script call: 
$gameParty.loseItem($dataItems[$gameVariables.value(28)], 1);

To save 1 selected item.

2) I then switch the party inventories using another plugin and use another script call:
$gameParty.gainItem($dataItems[$gameVariables.value(28)], 1);

To regain the selected items, thus by repeating this method the player would have only the selected items in battle. This worked.

3) However, the script call only loses/gains one item. If the player had 4 potions, for example, I would like all 4 potions to be lost/gained in one go.
Thus, I checked if a particular item was selected from the initial Select Item command and set another variable to count the possession count of this item.

4) So for example: If Item ID#2 selected, this other variable = possession count of item ID#2 

I then changed the script call to:
$gameParty.loseItem($dataItems[$gameVariables.value(28)], [$gameVariables.value(25)]);  

5) Now, I am able to lose the exact amount of the item I select. However:
$gameParty.gainItem($dataItems[$gameVariables.value(28)], [$gameVariables.value(25)]);  

Does not regain the same amount of the selected item. Instead I get an error: 
undefined is not a function

What am I doing wrong?
How can I regain the same amount of the item selected?
Is there a more efficient method to do step 4 instead of having a conditional branch check for every item (If I have to do this, I'd run it via a common event)

I have included images of my code. The inventory switch script call is not the problem as I've removed it and still obtained the same error message.


H1.PNG


H2.PNG

Original thread: https://forums.rpgmakerweb.com/threads/gaining-losing-item-script-call-help.65509/