Random loot problem

When the character opens a box, it should pull from a list and get a random result.
Ambush, gold, and nothing work fine.
Adding an item, weapon or armor doesn't work and I'm beating my head against the wall trying to figure out what I'm doing wrong.

This is the script I'm using

The control pulls a random number and stores it in (11)
var item = $gamevariables.value(11);
$gameParty.gainItem($dataItems[item], 1)

Please tell me it's something easy to fix
Hi there!
For weapons and armors you need to use a different script:
Weapons = $dataWeapons[Id]
Armors = $dataArmors[Id]

But you will need to make sure there is an existent weapon/armor/item with the ID stored on variable 11.
Hi there!
For weapons and armors you need to use a different script:
Weapons = $dataWeapons[Id]
Armors = $dataArmors[Id]

But you will need to make sure there is an existent weapon/armor/item with the ID stored on variable 11.
I have that as well
This script is not putting the items in the inventory
That's what is confusing me.

If it is the correct script, then I don't know what's wrong
The script you have shown here is correct then. The only two reasons I can see for it not working, with all the information you said, is that:

1 - If it is not a typo, your variable script call is missing a upper case:
Right: $gameVariables.value(11) Wrong: $gamevariables.value(11)

2 - The variable value is not right.

Can you try something like this and see what pops up on the console log?
JavaScript:
var item = $gameVariables.value(11);
console.log(item)
$gameParty.gainItem($dataItems[item], 1)

To use the console, press F12 or F8 and go to the "console" tab.

What I mean is for you to check the variable value.
You can also use the show text command with \v[id] to see the value.
The script you have shown here is correct then. The only two reasons I can see for it not working, with all the information you said, is that:

1 - If it is not a typo, your variable script call is missing a upper case:
Right: $gameVariables.value(11) Wrong: $gamevariables.value(11)

2 - The variable value is not right.

Can you try something like this and see what pops up on the console log?
JavaScript:
var item = $gameVariables.value(11);
console.log(item)
$gameParty.gainItem($dataItems[item], 1)

To use the console, press F12 or F8 and go to the "console" tab.

What I mean is for you to check the variable value.
You can also use the show text command with \v[id] to see the value.
The lowercase v was the problem.
Thank you so very much.
It works now.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/random-loot-problem.146732/