question

krislipscombe@gmail.com avatar image
krislipscombe@gmail.com asked

Issues With player_virtual_currency_balance_changed Event

We're currently having an issue with the player_virtual_currency_balance_changed. We're essentially using it to clamp the quantity of an energy currency in a range from 0 to 5. I've set it up so if we have a player_virtual_currency_balance_changed event that has the relevant VirtualCurrencyName and a VirtualCurrencyBalance outside of the prescribed range it triggers a CloudScript function that either adds or subtracts the relevant amount to get the currency to where we need to be.

While this initial function clears it up properly, I'm seeing a second triggering of the CloudScript. Looking at the relevant player_virtual_currency_balance_changed event, it has the expected VirtualCurrencyPreviousBalance (i.e. the balance before we cleaned it up with the CloudScript function), but the VirtualCurrencyBalance itself is identical to the VirtualCurrencyPreviousBalance. Obviously if these two fields are identical then a player_virtual_currency_balance_changed event shouldn't be fired, so it would appear there's a consistency issue of some kind going on here.

I've resolved this, for now, by doing a GetPlayerCombinedInfo call inside the CloudScript function and using the currency values returned from that to calculate any changes that need to be made, but this is less than ideal.

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

Which Title ID is this you're testing, so that we can have a look? It is definitely the case that if you call Add/SubtractUserVirtualCurrency with a 0 amount, you'll still generate a PlayStream event where the VirtualCurrencyPreviousBalance and VirtualCurrencyBalance are the same - that's by design.

If you want to have an action that runs a script that clamps the player VC balance to a range, I'd go this:

First, build the Rule for the player_virtual_currency_balance_changed event where you have two Condition Groups, so that you have an OR in there. One condition would just be VirtualCurrencyBalance, numeric value, is less than, 0. The other would then be VirtualCurrencyBalance, numeric value, is greater than, your max value. That runs the Cloud Script.

Then, in the script itself you have the VirtualCurrencyBalance in the context passed in. So you could just check context.VirtualCurrencyBalance, and decide whether to add, subtract, or do nothing (shouldn't hit this, but to be safe).

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.

krislipscombe@gmail.com avatar image krislipscombe@gmail.com commented ·

Title ID is 5DB8, which is our test environment. The setup you've described is exactly what I'm using, but it still has the issue described above.

If, for example, you take a look at user 334C81A03CDD23E5 and PlayStream event a20029816b164bf582c763eecbe95d50 you'll see that the user had an out of range HT currency at 9, whereas we're clamping from 0 to 5. We subtract 4 to get them back to 5, as you can see in the FunctionResult field. This, however, triggers the function again with event ID 93cd83445ef5466bb8cfdd75f3f4d353. Here you can see that both the VirtualCurrencyBalance and VirtualCurrencyPreviousBalance are 9. If they're both 9 then, surely, a player_virtual_currency_balance_changed should not have been issued? As it has been issued, it's clear that the currency balance has changed, but it's not represented in the VirtualCurrencyBalance field, which should be at 5 in this particular example. When I query GetPlayerCombinedInfo to get the user's current balance, that does return at 5, as expected, meaning we can get out of the actual update steps.

0 Likes 0 ·
brendan avatar image brendan krislipscombe@gmail.com commented ·

No, as I said, if you issue a call to AddUserVirtualCurrency or SubtractUserVirtualCurrency with a 0 value, there will still be an event generated. That's the expected behavior, and it's the only way to generate that event, with the VirtualCurrencyBalance and VirtualCurrencyPreviousBalance being equal.

I copied your script logic over to my own test title to validate everything, and with the PlayStream Rule you have defined set in my own title, everything appears to work as expected - if I update the player's VC balance for the one being checked to anything outside the valid range, the script is triggered, setting it back to the valid range. Since it looks like you have a fairly complex test case given all the events I see in your PlayStream debugger, I'd recommend narrowing this down to unit testing, so that you can check each of the steps.

If you can narrow this down to a specific set of repro steps that show the issue, please do let us know and we can test that locally to review the behavior.

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.