The inventory system is implemented in several logical cubes. This system manage :
- the reaction when an object is added to the inventory (to manage stacking behavior)
- the UI drawing and navigation in the inventory screen.
Note: In this chapter, an "item" means a pickable item.
Creating an itemEdit
A not stackable item is simply the standard pickable object created by Project Spark. There is nothing more to do, so its brain contains:
Creating a stackable itemEdit
A stackable item, must have some specific information defined in several variable and have some logic added (manage the way to pick up a stack of item).
- isStackable (boolean) : set to true to make this item stackable
- STACK_SIZE_MAX (number) : the maximum number of this item in a stack
- stackSize (number) : the amount of this object to add when picked up. Generally, it will be equals to "1", but if you want to collect 4 "Apple" when you pick an single "Apple" object in the game, you will set "stackSize=4". This will be usefull in crafting, as some recipe can create multiple items in a row (like arrows)
- Important: this variable must be set only if "isSkipStackInit=false" (trick for items that are stack / stackSize>1)
Object properties :
- Name (object name property) : To be able to determine if two project spark object will stack, the system will check the "isStackable" flag and the name of the object. the name is not a custom variable but the real name defined in the Project Spark Prop editor. So if i create two stackable objects with the same name, they will stack together even if they are totally differents (an apple and a lantern for exemple).
Note: The kode snapshot bellow contains a "isUsable", this mean that this stackable item is also usable (see bellow for more details).
Additionnaly to the variable initialization, a specific brain must be added in a given channel. This brain is needed to manage picking stackable items (for the case of an item is already a stack). This logic contains the standard [WHEN]interacted [DO]it pick up me
Here the Kode, to add the "pickableStackableItem" logic into the channel named "pickStackableChannel".
Creating a usable itemEdit
To create a usable item, you have two thing to do:
- Add at initialization of the object, [DO]isUsable=true
- Create a page in the item main brain named "Use", this page will be call when the item will be used (by clicking on "Use" from the inventory screen). Here an example of a "Use" page.
- Important: if you want to destroy the object after use, you must do it in a second pass of the page and you must drop it in the first pass. Indeed if you drop from inventory and destroy the item in the same code pass, the onItemRemove script will try to remove from inventory an already destroyed object, and your inventory will be desynchronized (this done in the following example using "page entered"/"else" so this script will be executed in two passes).
Creating an equipable itemEdit
Important: An equipable item cannot be stackable
To create an equipable item, just define the "isEquipable" boolean to "true", and add the standard pickable interaction.
Creating a storageEdit
A storage allows the player to loot objets (like chest), or to deposit its item to make space in its inventory (like bank).
The storage object will use the same logics as the player for its inventory, so here what you need to do to create a storage item.
- On the initialization
- Define the capacity of the storage (hard limite)
- Define its inventory will be displayed at the left of the screen (the right is reserved for the player inventory)
- Add the "InventoryContent" logic in the "inventorySystemChannel"
- finally switch to the next page, who contains the interaction behavior
- On interaction
- Define the "otherContainer" variable of this store equals to the source of interaction (player)
- Define the "otherContainer" variable of the player as this storage
- Define the "activeContainer" variable to this storage or the player (use to tell which inventory will have the focus at opening)
- Add the "InventoryManagement" logic to this storage in the given channel ("playerControlChannel") -> see this for more detail about this
- Add the "InventoryManagement" logic to the player in the given channel ("playerControlChannel") -> see this for more detail about this