question

rootsnwonky avatar image
rootsnwonky asked

How to get variable from GetCatalogItems on server?

First call this func on client:

public void MakeRent()
    {
        PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest()
        {
            FunctionName = "RentItem",
            FunctionParameter = new
            {
                ItemId = "Colt",
                CatalogVers = "Pistols"
            },


            GeneratePlayStreamEvent = true,


        }, OnRent, OnPlayFabError);
    }

Then server-side revision. I use this: https://docs.microsoft.com/en-us/rest/api/playfab/client/title-wide-data-management/getcatalogitems?view=playfab-rest)

But always see nothing on the return.

handlers.RentItem = function(args) {
    
    var GetCatalogItemsResult = server.GetCatalogItems({ "CatalogVersion": args.CatalogVers });
    
    for(var catalogItem in GetCatalogItemsResult.Catalog)
    {
        if(catalogItem.ItemId === args.ItemId)
        {
            return catalogItem.ItemId; // test
        }
    }
}
   

For this example:

args.CatalogVers is "Pistols"

args.ItemId is "Colt"

This is a test. At the finish i need check virtual currency price for this item on the server-side by this way:

var ItemPrice;

if(catalogItem.ItemId == args.ItemId){

	ItemPrice = catalogItem.VirtualCurrencyPrices // not working at this phase

	ItemPrice = catalogItem.VirtualCurrencyPrices["GL"] // same

        } 
CloudScript
12.png (8.2 KiB)
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

·
rootsnwonky avatar image
rootsnwonky answered

Solved:

handlers.RentItem = function(args) {
    
    
    var GetCatalogItemsResult = server.GetCatalogItems
({ CatalogVersion: args.CatalogVers });
    
    for(var catalogItem in GetCatalogItemsResult.Catalog)
    {
        var item = GetCatalogItemsResult.Catalog[catalogItem];
        
        if(item.ItemId == args.ItemId)
        {
            ItemPrice = item.VirtualCurrencyPrices["GL"];
            return ItemPrice;
        }
    }
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.