lukewaffel avatar image
lukewaffel asked

CloudScript check user VC before subtracting?

Hi there!

First of all, I've used PlayFab a few years back and I totally loved it. But seeing how far you guys have come, wow! It's truly amazing to see the amazing changes this service has gone through. Congratz guys!

So, for my question. (Hopefully) soon I'll start the design and development of a new multiplayer game. And because I have had so many good times with PlayFab, I'll obviously choose PlayFab as the player management backend. Ofcourse my game will incorporate purchasable items and stuff like that, so I'd like to handle these using the CloudScript feature. Since CloudScript has full access of the server API it's able to remove VC, grant items, and other stuff. There was one thing I couldn't find however. That's the possibility to check the user's (or character's) current VC. I thought maybe the subtract currency will give an error if there isn't enough VC left, but I could only see errors for InvalidVirtualCurrency and InvalidParams.

Is there any way to check if there is enough VC left before subtracting it? Also, what will the SubtractVC function return if there isn't enough? Just 0?

Thanks for creating this awesome platforms guys!

apisCloudScriptPlayer Inventory
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

Thanks! My first question would be, why not just define the VC prices in the catalog directly, and use PurchaseItem? That way, you wouldn't have to worry about that at all.

The virtual currency system is specifically designed to be flexible, and to allow currency to go negative, if you're using the Subtract... API call. It's only if you're using PurchaseItem that we ensure the transaction only takes place if the player has the VC. If you want to check the player's VC balance, you can get it from a call to get the player's inventory, or you could just use the GetUserVirtualCurrency option in the InfoRequestParameters of the GetPlayerCombinedInfo API call.

10 |1200

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

lukewaffel avatar image lukewaffel commented ·

My fault, I didn't even think of that. I was thinking about using cloud script to make everything more secure, but sending a purchase item request from the client would be just as secure right? Since you wouldn't have to manually supply the currency in the request since it's retrieved from the stored player data on the playfab servers.

0 Likes 0 ·
brendan avatar image brendan lukewaffel commented ·

Correct - we take care of making sure the player has enough VC, grant the item, and remove the VC from their balance.

0 Likes 0 ·

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.