-
Notifications
You must be signed in to change notification settings - Fork 0
MagpieInventoryContents
In addition to the basic Get() method, Magpie contains a number of methods for fetching lists of contents with various sorting types.
Many of the methods on this page return an Item Stack. Item stacks are a struct which contain two pieces of information:
| Property | Type | Description |
|---|---|---|
| item | * | The item which this stack represents |
| quantity | number | The number of items represented by this stack |
Yes, I'm documenting this on both pages.
Returns: ItemStack or undefined
| Parameter | Type | Description |
|---|---|---|
| item | * | The item to look up in the inventory |
Retrieve information about the item from the inventory. If the item exists in the inventory, it will return an ItemStack. (Stacking mode will be disregarded).
Returns: Array
| Parameter | Type | Description |
|---|---|---|
| * | The pocket to fetch the contents of (optional, defaults to undefined) |
Returns an array containing the contents of a specified pocket. If no pocket is specified, it will return the contents of the entire inventory instead. The returned array will contain ItemStacks representing the type and quantity of each item.
The returned array will be sorted by item quantity.
Returns: Array
| Parameter | Type | Description |
|---|---|---|
| * | The pocket to fetch the contents of (optional, defaults to undefined) |
Returns an array containing the contents of a specified pocket. If no pocket is specified, it will return the contents of the entire inventory instead. The returned array will contain ItemStacks representing the type and quantity of each item.
Usage of this method requires some setup. Items must be either a struct instance or a GameMaker object instance with a name variable containing a string, as this is what Magpie will look for to sort the list alphabetically. By default, calling this method will crash the game; reading the error message and acting accordingly is the barrier for entry for using this (otherwise free) library.
If used correctly, the returned array will be sorted by item name.
Returns: Array
| Parameter | Type | Description |
|---|---|---|
| * | The pocket to fetch the contents of (optional, defaults to undefined) | |
| sort_function | * | A function to sort the list by; see below (optional, ignored if not provided) |
Returns an array containing the contents of a specified pocket. If no pocket is specified, it will return the contents of the entire inventory instead. The returned array will contain ItemStacks representing the type and quantity of each item.
You may specify your own sorting function. Sorting functions should take two ItemStacks as parameters, and return a -1, 0, or +1 depending on which value is to be listed first. For example, this is the sorting function used by the ByQuantity method:
function(a, b) {
return a.quantity > b.quantity;
}
If no sorting function is provided to the method, the array will be stored in a random order.
Returns: Array<*>
| Parameter | Type | Description |
|---|---|---|
| sort_function | * | A function to sort the list by; see below (optional, ignored if not provided) |
Returns an array containing every item pocket in the inventory.
You may specify your own sorting function. Sorting functions should take two item pockets as parameters (those being whatever you used when you added an item to one), and return a -1, 0, or +1 depending on which value is to be listed first. For example, a common general sorting function might be:
function(a, b) {
return a > b;
}
If no sorting function is provided to the method, the array will be stored in a random order.