question

brendan avatar image
brendan asked

Replenishing Consumables

thefacelessj
started a topic on Tue, 16 September 2014 at 3:32 AM

My game has 8 power ups, which can be bought with ingame credits, or earned in game, and then used at will in game.

What is the best way to keep track of these items. I've noticed that buying a consumable puts a new instance of the item in the player's inventory, rather than increasing the amount of that item (i.e increasing uses remaining). Obviously, this means I'd need to keep track of potentially hundreds of instance id's to know if the user has any power ups available. My current approach instead is to maintain a local copy of the items and counts and store that in the player's UserData.

However, this approach means, when purchasing a new power up with ingame credits, I need to call PurchaseItem, ConsumeItem, and UpdateUserData. 3 http requests in a row, to perform a single action, which for slow connections can be a bit of a pain, since I need to wait for success responses to the first two requests.

Is there a better way to handle recharging item counts?

Thanks,

Josh

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

Best Answer
gwertzman said on Tue, 16 September 2014 at 8:39 AM

I know of two different ways to handle this today.

The first is to use the current catalog & inventory system, but go through the player's inventory creating a total "count" of available consumables which you then show to the player. You can see a good demo of this model in the AngryBots demo which is linked from our SDK page on GitHub (https://github.com/PlayFab/UnityPlayFab_AngryBots). There's code in there to go through the whole inventory and add up how many of which consumable the player has, and then when a player uses a consumable up, to "balance it out" on the server by consuming one of the available server-side items.

The other, less obvious way is to just use a virtual currency for this. Create one virtual currency for each powerup. You can see virtual currency to players through bundles --- when you want to sell a powerup w/ in-game credit, create a bundle that might cost, say 10 gold coins, but provides 2 powerups units.

If your game runs on the client, you will need to turn on the "Allow clients to add virtual currency" option in the properties tab of your game, so your game can directly credit virtual currency units to your player for pickups in the game, etc.

We are looking at ways to improve this model -- in the future, we hope to have "stacking" consumables available directly in the catalog. But for now, these are two workarounds that should solve the problem.


7 Comments
gwertzman said on Tue, 16 September 2014 at 8:39 AM

I know of two different ways to handle this today.

The first is to use the current catalog & inventory system, but go through the player's inventory creating a total "count" of available consumables which you then show to the player. You can see a good demo of this model in the AngryBots demo which is linked from our SDK page on GitHub (https://github.com/PlayFab/UnityPlayFab_AngryBots). There's code in there to go through the whole inventory and add up how many of which consumable the player has, and then when a player uses a consumable up, to "balance it out" on the server by consuming one of the available server-side items.

The other, less obvious way is to just use a virtual currency for this. Create one virtual currency for each powerup. You can see virtual currency to players through bundles --- when you want to sell a powerup w/ in-game credit, create a bundle that might cost, say 10 gold coins, but provides 2 powerups units.

If your game runs on the client, you will need to turn on the "Allow clients to add virtual currency" option in the properties tab of your game, so your game can directly credit virtual currency units to your player for pickups in the game, etc.

We are looking at ways to improve this model -- in the future, we hope to have "stacking" consumables available directly in the catalog. But for now, these are two workarounds that should solve the problem.


thefacelessj said on Tue, 16 September 2014 at 8:10 PM

The virtual currency workaround sounds perfect!

Thanks!


thefacelessj said on Thu, 18 September 2014 at 12:04 AM

Is it possible to put virtual currencies into random results tables? I.e To have a bundle which provides the player with 5 random power up units.


thefacelessj said on Thu, 18 September 2014 at 12:14 AM

Nevermind, seems I can put the currencies in bundles, and then award the bundles from the random result tables


facelessj said on Tue, 07 October 2014 at 1:24 AM

Is it possible to update multiple virtual currencies with a single call? At the moment, I keep track of power up usage, and then do a single batch update when the level ends , since the SDK and set up I have uses blocking HTTP requests. This becomes a little bit of a problem when I want to update 8 power up currencies individually with Add/SubtractUserVirtualCurrency one by one.

Just wondering if there is a method that I can use to update all the currencies at once. I.e can I pass an array of virtual currencies in those calls?


Brendan Vanous said on Wed, 08 October 2014 at 3:06 PM

No, the AddUserVirtualCurrency and SubtractUserVirtualCurrency calls are designed to only take a single VC at a time. For the subtract operation, the failure case could be tricky for the title to interpret without significantly more info on the specifics of what worked and didn't work, though you could create a bundle of multiple VCs for the Add case.


Brendan Vanous said on Tue, 09 December 2014 at 7:01 PM

Hi Josh,

FYI - we now also have the ability for virtual currencies to regenerate over time. Have a look at the Economy tab in the Game Manager for more information.

Brendan

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.