Gaining Items via Array instead of Integers

As I was making a tweak on making items, I have something in mind. So basically, when you make an actor / party gain an item, you would do:

$game_party.gain_item($data_items[1], 2)where 1 is the item id and 2 then amount. Now, I remember Tsukihime mentioned me about using a loop. I thought of making a loop inside the array where it gets at least 1 or more item ids. What I did was:

foods = [1,2,3,4,5]$game_party.gain_item($data_items[foods[0..foods.size]], 2)You will find it crazy as to gain item somehow only accepts an integer over an array. I have a question about this then, how can I make sure that I can gain all the items of the item id I indicated on foods? Is there a more functional way of gaining an item except making use of the gain_item command via game party? Or I have to make tons of gain item?
foods.each { |food| $game_party.gain_item($data_items[food], 2) }


Not crazy. Your problem is that $data_items[] requires an integer for the array element. A range or another array is not a valid array index. And even if it were, gain_item only accepts ONE item and its quantity.
foods.each { |food| $game_party.gain_item($data_items[food], 2) }

Not crazy. Your problem is that $data_items[] requires an integer for the array element. A range or another array is not a valid array index. And even if it were, gain_item only accepts ONE item and its quantity.
You're awesome Shaz! You saved me from making tons of gain items 🙂

You can lock this as it has been solved.
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/gaining-items-via-array-instead-of-integers.24092/