As the player is moving around the stage, they can use the Z Key to pick up items from the green boxes. This starts off a chain of events which differs slightly depending if the player already has the item in their inventory. The common thing between the two cases, is that as soon as the player picks up an item, the FoundItem text object will be set to visible, and show the player what item and how many they have picked up. The text object will then fade out.
If the player already has the item in their inventory, the value for the corresponding key in the dictionary is updated, and then the functions to update and save the inventories are called.
If the player does not have the item, then a new value needs to be added to the correct array. First, we check which array is needed by comparing the instance variable ItemCat on the ItemBox object with the Inventories family and pick the array that matches. Then, if the array already has items in, we simply push a new value (ItemBox.ItemID) to the back of the Y axis. If the array is empty, we set the value at (0,0) to ItemID stored in the ItemBox the player interacted with. Once the item has been added to the inventory, the save function is called.
When the inventory is open, the player can also use the Z Key to drop an item. This will simply remove the item from the inventory. If the player has more than one of a given item, they will drop one at a time until none are left.
If the Z key is pressed when the InvOpen Boolean is true, the game will check which inventory the player is currently looking at to ensure that the correct array is picked to remove the item from.
When the player only has a single copy of an item, its dictionary entry is set to 0 and the array size adjusted for the dropped item:
Sub-event Condition
Inventories ▶︎ CategoryID = CurrentInvID
Sub-event Condition
Dictionary ▶︎ Key ItemData.Get("items." & CurrentItemID & ".name") = 1
Sub-event Action
Dictionary ▶︎ Set key ItemData.Get("items." & CurrentItemID & ".name") to value 0
Sub-event Condition
Inventories ▶︎ Y size = 1
Sub-event Action
Inventories ▶︎ Set value at (0,0) to 0
Functions ▶︎ Call UpdateArray (ArrayName: CurrentInvCat)
Functions ▶︎ Call SaveInventories
Sub-event Condition
Inventories ▶︎ Y size > 1
Sub-event Condition
System ▶︎ CurrentInvPage = 0
Sub-event Action
Inventories ▶︎ Delete index CurrentItemSlot from Y Axis
Functions ▶︎ Call UpdateArray (ArrayName: CurrentInvCat)
Functions ▶︎ Call SaveInventories
Sub-event Condition
System ▶︎ CurrentInvPage > 0
Sub-event Action
Inventories ▶︎ Delete index CurrentItemSlot + (20*CurrentInvPage) from Y Axis
Functions ▶︎ Call UpdateArray (ArrayName: CurrentInvCat)
Functions ▶︎ Call SaveInventories
If the player has multiple copies of an item then when the Z key is pressed, the following event is called:
Sub-event Condition
Dictionary ▶︎ Key ItemData.Get("items." & CurrentItemID & ".name") > 1
Sub-event Action
Dictionary ▶︎ Set key ItemData.Get("items." & CurrentItemID & ".name") to value Dictionary.Get(ItemData.Get("items." & CurrentItemID & ".name")) -1
Functions ▶︎ Call SaveInventories