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.

No of items in variables

Status
Not open for further replies.
What I'm trying to do is to store in a variable the amount of a certain item. I tried this:
Code:
$game_variables[3] = $game_party.item_number[1]
but it didn't worked...

Another thing I don't know how to do is to count the total items. Not the total amount, but the amount of kinds of items (hard to explain). For example: I have 2 Potion, 3 High Potions and 1 Full Potion. In total I have 6 items and what I want is the 3 kinds of items.

The same goes to weapons and armor.

I tried to explain the best I could (my english isn't that good). If you don't understand something please tell me.

Thanks for reading ^_^

EDIT: Question No 1 Solved. Typed it wrong in the editor...
 

Zeriab

Sponsor

You can try pasting this code just above main:
Code:
class Game_Party
  ##
  # Returns the total amount of items in possession.
  #
  def no_items
    result = 0
    for key in @items.keys
      result += @items[key]
    end
    return result
  end
  ##
  # Returns the number of unique items in possesion.
  # I.e. how many different items the party has
  #
  def no_unique_items
    result = 0
    for key in @items.keys
      if @items[key] != 0
        result += 1
      end
    end
    return result
  end
end
Usage:
Code:
$game_variables[3] = $game_party.no_unique_items    # number of different items
$game_variables[3] = $game_party.no_items    # number of total items

Tell me if you can get this to work ^_^
 
Status
Not open for further replies.

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