Inventory Basics

Inventory is the set of items in the game like gems, medicines, food, weapons which can be carried by the player or can be placed in a level in the game. Each individual item in the inventory will be referred to as a inventory item or simply as an item.

Kheljs framework provides an inventory system that supports multiple inventories at the given game level and these inventories can be accessed by their names. However, there are two inventories that are special - the player inventory and the level inventory which can be accessed from any level. Game developers can add additional inventories at any level and use them for their own special purposes.

The inventory system provided by kheljs is not "one size fits them all" solution. If this type of inventory system is not suitable for your game, you are free to use something else or even create your own. However, understanding the default inventory system will give you ideas about how to create your own.

The Player inventory

The player inventory is the set of items the player carries during gameplay which can change over time as a result of spending some items or collecting new ones. The InventoryManager component is responsible for managing the inventory for the player in a given level. During initialization the InventoryManager reads the inventory of the player from the previously saved level state. If no inventory was saved previously, the InvemtoryManager loads a default inventory for the player for that level. See the programming guide section of the InventoryManager component to learn how to specify the default inventory for the player at a given game level in a declarative way.

The Game Level Inventory

The game level inventory is the set of items which are placed at various locations in the scene at a given level. This inventory is also managed by the InventoryManager component. During initialization, the InventoryManager component reads the level inventory from the previously saved level state. If no level inventory was found in the level state, a default level inventory is loaded. The programming guide section related to InventoryManager component describes how the default level inventory is specified.