Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Get the ID of the Item in an Array?

Well, Again with my questions...

It's possible to get the ID from an Item (From $data_items) that is in an array?:.

Example.

Code:
    itemsx = [1,4]
    for i in 1..itemsx.size
      if $game_party.item_number(i) > 0
        @data.push($data_items[i])
      end
    end

I have that, I want to push the Items with the IDS includes in the array = itemsx. (In this case Item 1 and Item 4.)

How can I do that?.

Thanks for read and help. :).
 
Actually, you'll need somthing like this:.

Code:
  itemsx = [1,4]
    for i in 0...itemsx.size
      itemid = itemsx[i]
      if $game_party.item_number(itemid) > 0
        @data.push($data_items[itemid])
      end
    end

Anyway, that should be what you need. All I did was fix the beginning of the for loop (Becasue arrays always start at 0, unless it is a database array like actors, which start at 1), and made it so that it looks for the item IDs stored in your array. If the player has it, then it is pushed into @data. I'm not 100% sure it'll work, though.
 
Thanks, but I get a Easier method  :lol:



Code:
    for i in 1...$data_items.size
      #Check if the Items are in the array and if number is more that 0
      if Relics::Relic_Items.include?(i) && $game_party.item_number(i) > 0
        @data.push($data_items[i])
      end
    end

It's very similar, but I get early  :shades:, Thanks anyway.

Resolved.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top