question

durmusalicollu avatar image
durmusalicollu asked

Virtual Currency goes negative

While I am testing my cloud server scripts, I used higher amount than player has with SubtractUserVirtualCurrency to test and virtual currency went negative. In my cloud script, I am checking current balance after SubtractUserVirtualCurrency, and there is no error.

Here are last 3 calls' returns I made. These called one by one to test.


{"PlayFabId":"1F9422E87DF811FB","VirtualCurrency":"GM","BalanceChange":-300,"Balance":-206}" }

{"PlayFabId":"1F9422E87DF811FB","VirtualCurrency":"GM","BalanceChange":-300,"Balance":-506}" }

{"PlayFabId":"1F9422E87DF811FB","VirtualCurrency":"GM","BalanceChange":-3,"Balance":-509}" }

I was checking player's Balance to continue progress in my code but apparently I can't trust that.

Unless checking player's current currency value and than verifying does he has enough currency to spend, It seems there isn't other solution, like when SubtractUserVirtualCurrency called, given error if player doesn't have sufficient virtual currency.

CloudScript
10 |1200

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

brendan avatar image
brendan answered

The SubtractUserVirtualCurrency call actually is specifically designed to allow the virtual currency balance go negative, since that's a requirement of some titles. The PurchaseItem call is designed to prevent using VC to purchase an item that the player does not have.

2 comments
10 |1200

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

durmusalicollu avatar image durmusalicollu commented ·

I see. Maybe, it can be nice to have a kind of reminder on the documentation side for balance can go negative.

Also I haven't test it but, how does AddUserVirtualCurrency works if player has negative amount? Does it increase counting like player has 0 balance or just adding it what player has in negative amount?

0 Likes 0 ·
brendan avatar image brendan durmusalicollu commented ·

It adds to whatever the player's current balance is. So if the current balance is -1 and you add 2, the new balance would be 1. We'll be sure to get the docs updated for those API calls, to make this clearer.

1 Like 1 ·
pdaz avatar image
pdaz answered

Just check if a player has enough money and then subtract currency.

Btw when the script is called twice at the same time it will let you go negative because of the delay. I don't know any solution for this yet. This also concerns purchasing item.

3 comments
10 |1200

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

brendan avatar image brendan commented ·

Yes, the issue with that is that multiple simultaneous calls to do that on a single player account could result in the balance going negative, since the calls are being processed simultaneously. Generally speaking, this is an issue you face with hacked clients - people attempting to cheat your game. At least one title chose to solve for this by temporarily banning accounts that went negative on the player VC balance as a result of one of these operations, in order to dissuade that behavior. That may be a bit extreme for most titles, but it is an option.

0 Likes 0 ·
Denzie Gray avatar image Denzie Gray brendan commented ·

@Brendan

Is this still the case in 2022?

0 Likes 0 ·
Weslley Xavier avatar image Weslley Xavier Denzie Gray commented ·

I believe it still is!

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.