question

Brent Batas (Lisk) avatar image
Brent Batas (Lisk) asked

Easiest way to reset a user's currency to zero?

My current approach is something like:

1. PlayFabServerAPI.GetPlayerCombinedInfoAsync() to get their current currency

2. PlayFabServerAPI.SubtractUserVirtualCurrencyAsync to subtract that exact amount

Is there any way to do it in a single API call, or is the way I am doing it the best way to do it?

I tried subtracting a large number, 999999, but I just ended up with a negative currency.

apis
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

That would be the way to do it for now (Get, then Subtract the balance), but we'll be providing a "Set" call for virtual currency shortly.

4 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.

plosnita avatar image plosnita commented ·

Hi,
Have you got around to creating the "Set" call?

Thank you,

Virgiliu

0 Likes 0 ·
brendan avatar image brendan plosnita commented ·

I realize this sounds like a trivial request, but we cannot make any changes to the service without having complete test coverage. So even just adding a "set vc" call requires an engineer to add a suite of tests. Given that we have finite resources, we have to schedule all work. We do that via a prioritization process that includes as a major factor, how many developers have asked for any given feature or change. As we haven't had many requests for this specific update, it's not something we've been able to prioritize over other, more requested features.

0 Likes 0 ·
Brent Batas (Lisk) avatar image Brent Batas (Lisk) brendan commented ·

I wonder if it's possible for you guys to write a Test Suite specification and make it publicly available, that way us developers can help you write tests for the features we want. Maybe it could be handled via pull requests or something; maybe available only to pro-tier+ if you need to vet.

0 Likes 0 ·
Show more comments
Tamer Nasser avatar image
Tamer Nasser answered

Any update on Set currency?

10 |1200

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

sasha.r@liveplaymobile.com avatar image
sasha.r@liveplaymobile.com answered

@Brendan hey, any update on Set functional? We are changing our process with currencies and we need Set. It's been 4 years already since your initial message. I can't imagine why it may take so much time for such simple functionality.

10 |1200

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

Rodrigo avatar image
Rodrigo answered

@sasha.r@liveplaymobile.com @Tamer Nasser

Here is the cloud script we used to set the a currency to a specific value.

//This is used to set the amount of a specific currency to the desired value
handlers.SetUserVirtualCurrency = function (args) {
    var targetBalance = args.targetBalance;
    var vc = args.vc;

    //log.debug("Target Balance: " + args.targetBalance + " VirtualCurrency: " + vc);

    var inventory = server.GetUserInventory({ PlayFabId: currentPlayerId});
    //log.debug("Virtual Currencies List: " + inventory.VirtualCurrency);

    var currentBalance = inventory.VirtualCurrency[vc];
    //log.debug("Current Balance: " + currentBalance);

    if (currentBalance < targetBalance){
      server.AddUserVirtualCurrency({ PlayFabId: currentPlayerId, VirtualCurrency: vc, Amount: targetBalance - currentBalance });
      //log.debug("Add User Currency: " + targetBalance - currentBalance);
    }
    else if (currentBalance > targetBalance){
      server.SubtractUserVirtualCurrency({ PlayFabId: currentPlayerId, VirtualCurrency: vc, Amount: currentBalance - targetBalance });
      //log.debug("Substract User Currency: " + targetBalance - currentBalance);
    }

};


Ensure that the vc is a valid virtual currency code.



To run this for every player you have to:

1. Go to Dashboard -> Automation -> Scheduled Tasks

2. Create a New Scheduled Task that runs on every player on a segment.

3. Segment -> All Players

4. Add + Action -> Execute Cloud Script and find the function created (must be deployed in order to show there)

5. Set the arguments to

{
  "targetBalance": 2000, //The target amount
  "vc": "SC" //Your virtual currency CODE
}
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.