question

luizcarlos-bs avatar image
luizcarlos-bs asked

How to get virtual currency in cloudscript?

I'm trying to get virtual currency, but here is the problem. Using cloudscript I did:

 var result2 = PostAsync("", "https://.playfabapi.com/Server/GetUserInventory", json2).Result;

as return, the json2 is:

 GetUserInventoryRequest inventoryRequest = new GetUserInventoryRequest();
             inventoryRequest.PlayFabId = playFabId;
             string json2 = JsonConvert.SerializeObject(inventoryRequest);

I have a very long text as result, and I don't know now how to filter just the info I want. For instance, I want to make a public string vcAmount; and fill vsAmount with the current player VirtualCurrency amount, someone can help me with the code? I can't find the answer anywhere.

apisCloudScript
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

·
Neils Shi avatar image
Neils Shi answered

If you want to get a player’s Virtual Currencies in CloudScript, you can refer to the following code:

 handlers.GetVirtualCurrency = function(args,context){
     var targetId = null;
     if (args && args.targetId)
         targetId = args.targetId;
       
     var targetCurrency = null;
     if (args && args.targetCurrency)
         targetCurrency = args.targetCurrency;
       
     var GetUserInventoryResult = server.GetUserInventory({
         PlayFabId:targetId
     });
       
     var vsAmount = GetUserInventoryResult.VirtualCurrency;
     log.debug(vsAmount); //The player can have multiple virtual currency, these are the overview of currencies owned by players.
       
     log.debug(vsAmount[targetCurrency]); //You can get the specific currency by this.
       
 }

Please note that the GetUserInventoryResult.VirtualCurrency is not a string type, but an object type, as the player may have multiple Virtual Currencies.

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.