Methods
Inventory:addItem(item: string|Item, ignore_convert: boolean?)
Adds an item to this inventory, sending it to it's default storage
Arguments:
item: string|Item | The Item class represents all types of item in Kristal. |
ignore_convert: boolean? |
Returns:
1: Item|nil |
Inventory:addItemTo(storage: string|table, index: integer?, item: string|Item, allow_fallback: boolean?)
Adds an item to this inventory
Arguments:
storage: string|table | |
index: integer? | |
item: string|Item | The Item class represents all types of item in Kristal. |
allow_fallback: boolean? |
Returns:
1: Item|nil |
Inventory:clear()
Completely empties the inventory and removes all its storages
Inventory:getDefaultStorage(item_type: string|Item, ignore_convert: boolean?)
Gets the default storaged used to store items of type item_type
@param item_type
— An item type or an Item instance to get the type from
Arguments:
item_type: string|Item | An item type or an Item instance to get the type from |
ignore_convert: boolean? |
Returns:
storage: table |
Inventory:getFreeSpace(storage: string|table, allow_fallback: boolean?)
Gets the amount of free space in the specified storage
Arguments:
storage: string|table | |
allow_fallback: boolean? |
Returns:
1: integer |
Inventory:getItem(storage: string|table, index: integer)
Gets an item from the inventory, if it exists
Arguments:
storage: string|table | |
index: integer |
Returns:
1: Item|nil |
Inventory:getItemByID(item: string)
Gets an item in the inventory by its id, if it exists
Arguments:
item: string |
Returns:
1: Item|nil |
Inventory:getItemCount(storage: string|table, allow_fallback: boolean?)
Gets the number of items contained in the specified storage
@param allow_fallback
— Whether the fallback storage should also be included in the item count
Arguments:
storage: string|table | |
allow_fallback: boolean? | Whether the fallback storage should also be included in the item count |
Returns:
1: integer |
Inventory:getItemIndex(item: string|Item)
Gets the storage and index an item is stored at in this inventory, if it exists
Arguments:
item: string|Item | The Item class represents all types of item in Kristal. |
Returns:
storage: table|nil | |
index: integer|nil |
Inventory:getNextIndex(storage: string|table, index: integer?, allow_fallback: boolean?)
Gets the next open index for an item in the given storage
@param index
— The minimum index to check
@param allow_fallback
— Whether the fallback storage will be checked if the current target storage is full
@return id
— The id of the storage with an open slot
@return index
— The index of the open slot
Arguments:
storage: string|table | |
index: integer? | The minimum index to check |
allow_fallback: boolean? | Whether the fallback storage will be checked if the current target storage is full |
Returns:
id: string|nil | The id of the storage with an open slot |
index: integer|nil | The index of the open slot |
Inventory:getStorage(type: string)
Gets one of this inventory's storages
@param type
— The name of the storage
Arguments:
type: string | The name of the storage |
Returns:
storage: table |
Inventory:hasItem(item: string|Item)
Gets whether an item is in this inventory, in any storage
Arguments:
item: string|Item | The Item class represents all types of item in Kristal. |
Returns:
has_item: boolean | |
item: Item|nil |
Inventory:isFull(storage: string|table, allow_fallback: boolean?)
Gets whether a particular storage in this inventory is full
@param allow_fallback
— Whether the fallback storage should also be checked for space before declaring this storage full
Arguments:
storage: string|table | |
allow_fallback: boolean? | Whether the fallback storage should also be checked for space before declaring this storage full |
Returns:
full: boolean |
Inventory:removeItem(item: string|Item)
Removes an item from this inventory
Arguments:
item: string|Item | The Item class represents all types of item in Kristal. |
Returns:
1: Item|nil |
Inventory:removeItemFrom(storage: string|table, index: integer?)
Removes the item at index
of a specific storage in this inventory
Arguments:
storage: string|table | |
index: integer? |
Returns:
1: Item|nil |
Inventory:replaceItem(item: string|Item, new: string|Item)
Replaces one item in the inventory with another
Arguments:
item: string|Item | The Item class represents all types of item in Kristal. |
new: string|Item | The Item class represents all types of item in Kristal. |
Returns:
1: Item|nil |
Inventory:setItem(storage: (string|table)?, index: integer?, item: (string|Item)?)
Sets the item stored at index
of a particular storage
Arguments:
storage: (string|table)? | |
index: integer? | |
item: (string|Item)? | The Item class represents all types of item in Kristal. |
Returns:
1: Item|nil |
Inventory:swapItems(storage1: string|table, index1: integer, storage2: string|table, index2: integer)
Swaps the position of two items in the inventory
Arguments:
storage1: string|table | |
index1: integer | |
storage2: string|table | |
index2: integer |
Inventory:tryGiveItem(item: string|Item, ignore_convert: boolean)
Tries to give an item to the player, and returns an appropriate text to display depending on success
@return success
— Whether the item was successfully picked up
@return result_text
— The text that should be displayed
Arguments:
item: string|Item | The Item class represents all types of item in Kristal. |
ignore_convert: boolean |
Returns:
success: boolean | Whether the item was successfully picked up |
result_text: string | The text that should be displayed |
Fields
Inventory.storage_enabled: boolean
Whether the storage
storage (overflow accessed in the SAVE menu) is enabled
Inventory.storages: table<string, table>
A table containing all the storage tables available for this inventory