Skip to content

MagpieBasicManagement

Dragonite edited this page Feb 16, 2021 · 3 revisions

These are the basic inventory management functions of Magpie. Magpie makes use of a single struct, which contains several methods.

Magpie makes some use of generic programming (hence why I keep calling it that). The exact data you input into it doesn't much matter as long as it's the general shape that it expects.

new MagpieInventory()

Constructor

Create an inventory. No other initial setup is needed.

MagpieInventory::Add(item, quantity*, pocket*)

Returns: N/A

Parameter Type Description
item * An item to add
quantity number The number of items to add (optional, defaults to 1)
pocket * The pocket the item belongs to (optional, defaults to undefined)

Add an item to the inventory. The item can be anything, but unless you like making yourself miserable this should probably be one of three things:

  • A struct containing an item definition
  • An ID referencing an item definition somewhere else
  • You really shouldn't use anything besides the first two but the unit test uses a string and I want to point out that's probably not going to work in practice

Likewise, the item pocket can be anything, but unless you want your code to be a mess it should look similar to the above, also. Other than that, I'm not going to tell you how your game should be set up. This defaults to undefined, which will cause the item to be added to the inventory without being added to a pocket.

The quantity is the number of items you want to add.

MagpieInventory::Remove(item, quantity*)

Returns: N/A

Parameter Type Description
item * An item to remove
quantity number The number of items to remove (optional, defaults to 1)

Remove an item from the inventory. See the above rules for what an item should be. If the item does not exist in the inventory, nothing will happen.

The quantity is the number of items you want to remove.

MagpieInventory::Clear()

Returns: N/A

Erase everything in the inventory.

MagpieInventory::SetStackingMode(mode)

Returns: N/A

Parameter Type Description
mode boolean True for items to be clustered together in stacks when fetching the inventory as a list, false for them to be listed individually instead

Set the stacking mode for the inventory. Setting this to true will cause items to be grouped together when fetching the inventory contents as a list:

Potion x1
Super Potion x2
Elixir x3
Stick x10

Setting the stacking mode to false will cause items to be listed individually instead:

Potion
Super Potion
Super Potion
Elixir
Elixir
Elixir
Stick
Stick
Stick
Stick
Stick
Stick
Stick
Stick
Stick
Stick

MagpieInventory::Get(item)

Returns: { item, quantity } 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 a struct containing item as the item type and quantity as a number representing the number of items in the inventory. (Stacking mode will be disregarded).

Clone this wiki locally