Stacks
Economy v2 is now Generally Available. For support and feedback, go to the PlayFab Forum.
Id can be stored as stacks of the item each with their own amount and differentiated by StackId. If not specified, inventory actions will typically use the default stack with the StackId: default The default stack can be deleted. The next time an add/transfer occurs without a StackId (or uses the default StackId), the default stack is recreated
Managing Inventories and Stacks
The following are a detailed breakdown of the Inventory APIs and their interactions with Stacks.Add Inventory Items
In theAddInventoryItems API, you can define a StackId in the Item parameter. This parameter defines either the stack that is being increased or the ID of the new stack being created.
An example AddInventoryItems request with a StackId:
NewStack or add 5 to the existing NewStack if it already existed
Subtract Inventory Items
In theSubtractInventoryItems API, the StackId is used to define which stack is being subtracted from. In addition, there’s a DeleteEmptyStacks boolean that can be set which deletes the stack if the subtracted amount results in the stack having an amount of 0.
Trying to subtract more from a stack than the current stack amount will throw an error.
An example SubtractInventoryItems request with StackId:
NewStack and would delete the stack if it had the exact amount of 5.
Update Inventory Items
In theUpdateInventoryItems API, you can define a StackId in the Item parameter. This parameter defines either the stack that is being updated or the ID of the new stack being created.
An example UpdateInventoryItems request:
NewStack or set the amount of NewStack to 5 if it already existed
Delete Inventory Items
TheDeleteInventoryItems API is used to delete an entire stack of items from a player’s inventory. A StackId can be provided to define the specific stack of the Item to be deleted.
An example DeleteInventoryItems request:
Purchase Inventory Items
ThePurchaseInventoryItems API uses the catalog-defined price of the item, and deducts the cost from the player’s inventory and exchanges it with the desired amount of the item. You must specify the Item you wish to purchase and the Amount of the item you wish to purchase.
When you make purchases with stacks, there are a few parameters that are relevant:
- For
PriceAmountsyou can define an optionalStackIdfor each price item (that is, the items being spent) to define which stack the spent items will be deducted from - For the
Itemobject, you can define an optionalStackIdthat represents the stack the receiving items will be placed in - There’s a
DeleteEmptyStacksboolean that can be set which deletes the stack if the subtracted amount results in the stack having an amount of 0.
For more details on purchasing items, see PurchaseInventoryItems.
PurchaseInventoryItems request with stacks:
Transfer Inventory Items
When you use theTransferInventoryItems API with stacks, there are a few relevant parameters:
- In the
GivingItemobject, you can define an optionalStackIdthat represents the stack the given items will be taken from - In the
ReceivingItemobject, you can define an optionalStackIdthat represents the stack the receiving items will be placed in - There’s a
DeleteEmptyStacksboolean that can be set which deletes the stack if theGivingItemamount results in the stack having an amount of 0
TransferInventoryItems request with stacks:
ExecuteInventoryOperations API
You can use theStackId and DeleteEmptyStacks parameters in the Operation objects in the ExecuteInventoryOperations API. These parameters allow you to batch multiple inventory operations using stacks.
An example ExecuteInventoryOperations request with stacks:
Adding Custom Properties with DisplayProperties and NewStackValues
You can set custom item properties to inventory Items with theDisplayProperties parameter. Setting properties can be done in the AddInventoryItems, PurchaseInventoryItems and TransferInventoryItems APIs, but only when a new stack is created. To set Display Properties for new items, the NewStackValues parameter must be set in the API request.
An example AddInventoryItems request with NewStackValues:
UpdateInventoryItems API can be used to directly modify properties.