Gacha (random item generator) SOS

So to preface I'm an RPG/MV baby. I'm just trying to create a random item generator. I've figured out how to do so using an event creation and a common event. However, I can't get the text box that appear after player receives the item, to display the item name and not the random number. The corresponding item appears in the player inventory but I want the name to display in the text box once the player receives the item. What am I missing in my script? Common Events? Control Variable? Etc...

my common event reads as follows

Name: Gacha

Contents
Control Variables : #0020 LOOT ROLLER = Random 1..10
Script : var item = $gameVariables.value(20);
$gameParty.gainItem($dataItems[item.name], 1);
Text : None, Dim, Bottom
You've obtained a \ii\v[20]!


Does my common event 20 need to have specified item names for each number instead of pulling from the item database I have? Please send help ;u;
Thank you.

I've moved this thread to RPG Maker MV. Thank you.


It's because in the show text window you are displaying the value of the variable, which is the id of the item, not the item itself. A solution would be to set the item name as the value of another game variable and use that one instead in the message window. Let's say I use variable 21 for that:
Code:
var item = $dataItems[$gameVariables.value(20)];
$gameVariables.setValue(21, item.name);
You reference arrays by ids, not by names. I'm surprised it's actually giving you the item, as there would be no such thing as $dataItems[5.name]. And unless you have a message plugin that gives you additional escape codes, you have to put the item name into a variable as well.

Try this (which is an expansion on the above suggestion):
Code:
Control Variables: #0020 LOOT ROLLER = Random 1..10
Control Variables : #0021 LOOT NAME = Script: $dataItems[$gameVariables.value(20)].name;
Script: $gameParty.gainItem($dataItems[$gameVariables.value(20)], 1);
Text: You've obtained a \v[21]!
Moved to: RPG Maker MV
It's because in the show text window you are displaying the value of the variable, which is the id of the item, not the item itself. A solution would be to set the item name as the value of another game variable and use that one instead in the message window. Let's say I use variable 21 for that:
Code:
var item = $dataItems[$gameVariables.value(20)];
$gameVariables.setValue(21, item.name);

So sorry, my first post, I'll try to be more mindful next time 😅
You reference arrays by ids, not by items. I'm surprised it's actually giving you the item, as there would be no such thing as $dataItems[5.name]. And unless you have a message plugin that gives you additional escape codes, you have to put the item name into a variable as well.

Try this (which is an expansion on the above suggestion):
Code:
Control Variables: #0020 LOOT ROLLER = Random 1..10
Control Variables : #0021 LOOT NAME = Script: $dataItems[$gameVariables.value(20)].name;
Script: $gameParty.gainItem($dataItems[$gameVariables.value(20)], 1);
Text: You've obtained a \v[21]!


😢omg thank you so much!!!!! It was driving me crazy.

Original thread: https://forums.rpgmakerweb.com/threads/gacha-random-item-generator-sos.123918/