I always get my self mixed up in for loops - Especially in ruby. So lets start with this:
There are three things to focus on, the hash - in the module, then the private methods: create_master_item_list and create_inventory_hash.
create_master_item_list will create an array of RPG objects based on their type. That's fine, we then need to take that array of items, the hash it came from and create something like:
You might be wondering, where is this information coming from?
When you call create_new_static_drop("Drop Two") you get are processing the Drop Two key, with its nested hashes, try it and inspect it.
So based on that, in the method: create_inventory_hash what do I have to do so that its tr_obj.item_id => inv.name - that is the id should match the name.
An example:
In Drop Two hash is item_type 2, armor with an ID 1 - in my test database that's leather armor. So the hash should be: 1 => leather armor.
the method that sets up or is responsible for setting up this hash is:
def create_inventory_hash(drop_inventory, troop_object) inv_hash = {} drop_inventory.each do |inv| troop_object.each do |tr_obj| inv_hash[tr_obj.item_id] = inv.name end end puts inv_hash.inspect endI hope my post was clear enough - I tend to fail at explaining things through text.
If you run the script and view the results in the terminal you'll see things are messed up.
module DROPS DROP_HASH = { "Drop One" => { :item_type => 0, :item_id => 1, :amount => 6, :currency_type => "GC", :currency_amount => 25 }, "Drop Two" => [ { :item_type => 2, :item_id => 1, :amount => 6, :currency_type => "GC", :currency_amount => 0 }, { :item_type => 1, :item_id => 1, :amount => 6, :currency_type => "GC", :currency_amount => 20 }, { :item_type => 2, :item_id => 20, :amount => 6, :currency_type => "RT", :currency_amount => 20 }, ] }endclass << DataManager alias kalacious_troop_drop_object create_game_objects def create_game_objects kalacious_troop_drop_object $kc_drop = Troop_Drop.new endendclass Troop_Drop def initialize @troop_drop_object = [] end def drop_object @troop_drop_object end def create_new_drop(item_type, item_id, amount, currency_type, currency_gain) if @troop_drop_object.any? @troop_drop_object.each do |drop| if drop.item_type == item_type and drop.item_id == item_id return false end end end drop_object = Troop_Drop_Object.new(item_type, item_id, amount, currency_type, currency_gain) @troop_drop_object.push(drop_object) end def create_new_static_drop(name) drops = DROPS:😀ROP_HASH[name] || [] drops = [drops] if !drops.is_a? Array drops.each do |drop| create_new_drop(drop[:item_type], drop[:item_id], drop[:amount], drop[:currency_type], drop[:currency_gain]) end end def get_drop_name create_master_item_list(@troop_drop_object) end def test_menthod $game_message.texts.push("example"); end private def create_master_item_list(inventory_object) drop_inventory = [] inventory_object.each do |inv| case inv.item_type when 0; item = $data_items[inv.item_id] when 1; item = $data_weapons[inv.item_id] when 2; item = $data_armors[inv.item_id] end if drop_inventory drop_inventory.push(item) end end create_inventory_hash(drop_inventory, drop_object) end def create_inventory_hash(drop_inventory, troop_object) inv_hash = {} drop_inventory.each do |inv| troop_object.each do |tr_obj| inv_hash[tr_obj.item_id] = inv.name end end puts inv_hash.inspect endendclass Troop_Drop_Object attr_reader :item_type attr_reader :item_id attr_reader :amount attr_reader :currency_type attr_reader :curency_gain def initialize(item_type, item_id, amount, currency_type = '', currency_gain = 0) @item_type = item_type @item_id = item_id @amount = amount @currency_type = currency_type @currency_gain = currency_gain endend
create_master_item_list will create an array of RPG objects based on their type. That's fine, we then need to take that array of items, the hash it came from and create something like:
Code:
{ 2 => what ever armor, 1 => what ever armor, 2 => what ever armor}
When you call create_new_static_drop("Drop Two") you get are processing the Drop Two key, with its nested hashes, try it and inspect it.
So based on that, in the method: create_inventory_hash what do I have to do so that its tr_obj.item_id => inv.name - that is the id should match the name.
An example:
In Drop Two hash is item_type 2, armor with an ID 1 - in my test database that's leather armor. So the hash should be: 1 => leather armor.
the method that sets up or is responsible for setting up this hash is:
def create_inventory_hash(drop_inventory, troop_object) inv_hash = {} drop_inventory.each do |inv| troop_object.each do |tr_obj| inv_hash[tr_obj.item_id] = inv.name end end puts inv_hash.inspect endI hope my post was clear enough - I tend to fail at explaining things through text.
If you run the script and view the results in the terminal you'll see things are messed up.