Gaining Items via Array instead of Integers

Status
Not open for further replies.

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
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?
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
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.
 
Last edited by a moderator:

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
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.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
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.
 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,860
Messages
1,017,038
Members
137,568
Latest member
invidious
Top