Module bzInventory :: Class bzInventory
[frames] | no frames]

Class bzInventory

source code

This object is a container for all object owned by a player. It can be used to retrieve names of object collected by the player or count number of element of a given type.

Exemple:
   # initialisation
   inventory = bzInventory()
   inventory.add (100, 'Health')
   
   # player grab a health potion pack
   inventory.add (50, 'Health.000')
   print "Player has %d health points"%(inventory.count ('Health'))
   
   # player suddenly get a bomb in his ass
   inventory.add (-120, 'Health')
   print "Player now has %d health points"%(inventory.count ('Health'))
   
   #display the detailled content of the player inventory
   print "player inventory is: ",inventory.getContent()


Instance Methods
bzInventory
__init__(self, content=None)
Content of inventory can be initialized.
source code
 
__repr__(self) source code
 
__str__(self) source code
integer.
add(self, quantity, objname)
Add a 'quantity' number of object of type 'objname' in the inventory.
source code
integer
count(self, objname)
Return the number of element in the inventory of type 'objname'
source code
list of [integer, string]
getContent(self)
Returns the content of the inventory.
source code
Instance Variables
list of [integer, string]. inventory
a list of all object contained in the inventory and the associated quantity.
Method Details

__init__(self, content=None)
(Constructor)

source code 
Content of inventory can be initialized. Default content is empty(None).
Parameters:
  • content (List of [integer, string]) - List of [quantity, object_name]
Returns: bzInventory
N/A

add(self, quantity, objname)

source code 
Add a 'quantity' number of object of type 'objname' in the inventory. If the 'quantity' number is negative, quantities of objects named 'objname' or 'objname.xxx' are decremented until 'quantity' elements has been removed or there's no left element of that type in the inventory.
Parameters:
  • quantity (integer) - the number of added element.
  • objname (string) - the name of the object.
Returns: integer.
the number of object of type 'objname' in the inventory.

count(self, objname)

source code 
Return the number of element in the inventory of type 'objname'
Parameters:
  • objname (string) - the name of the object.
Returns: integer
the number of object of type 'objname' in the inventory.

getContent(self)

source code 
Returns the content of the inventory.
Returns: list of [integer, string]
the number of object of type 'objname' in the inventory.