question

protonjump avatar image
protonjump asked

How do you subscribe to the events in the Playfab API for Unity?

1 comment
10 |1200

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

protonjump avatar image protonjump commented ·

I accidentally submitted my question before completing it and do not know how to edit it. Here is what I have tried. In a class I have:

private PlayFabEvents playFabEvents;

playFabEvents.OnSubtractUserVirtualCurrencyResultEvent += UpdateCurrencyAmountText;
playFabEvents.OnAddUserVirtualCurrencyResultEvent += UpdateCurrencyAmountText;

public void UpdateCurrencyAmountText(ModifyUserVirtualCurrencyResult modifyUserVirtualCurrencyResult)
{
//Code to update text showing virtual currency
}

The intention of this is that any time the user's virtual currency changes, UpdateCurrencyAmountText will be called. However playFabEvents does not have a value assigned to it and I cannot find what to assign to it. So, am I going in the right direction here and if so, what will I assign to playFabEvents?

0 Likes 0 ·

1 Answer

·
Seth Du avatar image
Seth Du answered

The successful callback of AddUserVirtualCurrency and SubtractUserVirtualCurrency API call contains the change information, however, there are few things you may need to know.

  • We usually won’t allow players to change Virtual Currency via disable the option of “Allow client to subtract virtual currency” in Title Settings to prevent abusive use from the client.
  • Client won’t be able to keep track of PlayStream Events.

Hence, the common scenario will be subscribing the callback result of ExecuteCloudScript, where verification of gaming process will be done before the VC is changed via Server API.

In addition, clients may also call GetUserInventory API to retrieve the VC actively.

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.