question

Anant Sharma avatar image
Anant Sharma asked

Get Catalog Items Does Not Work

I'm using a cloud script which let user buy an item from the catalog,pretty simple stuff

here is the code for the cloudscript function

var PurchaseWeapon = function (args) {
    var weaponToPurchase = null;
    var gameCatalog = server.GetCatalogItems({ CatalogVersion: "Main" });
    var playerItemsRank = server.GetUserReadOnlyData({ PlayFabId: currentPlayerId, Keys: ["WeaponsRank"] });
    var playerInventory = server.GetUserInventory({ PlayFabId: currentPlayerId });
    for (var i = 0; i < gameCatalog.Catalog.length; i++) {
        log.debug(gameCatalog.Catalog[i].ItemId);
        if (gameCatalog.Catalog[i].ItemId === args.purchaseWeaponName) {
            weaponToPurchase = gameCatalog.Catalog[i];
        }
        else {
            log.debug("Cannot Find Weapon Name " + args.purchaseWeaponName);
            return;
        }
    }
    if (parseInt(playerItemsRank.Data["WeaponsRank"].Value) >= parseInt(weaponToPurchase.CustomData["Rank"])) {
        if (playerInventory.VirtualCurrency["MA"] >= weaponToPurchase.VirtualCurrencyPrices["MA"]) {
            server.GrantItemsToUser({ PlayFabId: currentPlayerId, ItemIds: [weaponToPurchase.ItemId] });
            server.SubtractUserVirtualCurrency({ PlayFabId: currentPlayerId, Amount: weaponToPurchase.VirtualCurrencyPrices["MA"], VirtualCurrency: "MA" });
            log.info("item name " + weaponToPurchase.ItemId + " granted to user for " + weaponToPurchase.VirtualCurrencyPrices["MA"] + " " + "MA");
        }
        else {
            log.error("cannot grant item " + weaponToPurchase.ItemId + " to user because required " + "MA" + " is " + weaponToPurchase.VirtualCurrencyPrices["MA"] + " and player have " + playerInventory.VirtualCurrency["MA"]);
        }
    }
    else {
        log.error("cannot grant item " + weaponToPurchase.ItemId + " to user because required rank is " + parseInt(playerItemsRank.Data["WeaponsRank"].Value) + " and player rank is " + parseInt(weaponToPurchase.CustomData["Rank"]));
    }
};

But the problem is that the get catalog item request does not return all the item in the catalogs and most importantly it does not find the user requested weapon for purchase in the catalog even when it's there!!!

Here are some screenshots to explainthe problem further

As you can see when i print all the item ids from the catalog in the debug log it shows only 2 items out of total 5 items in the main catalog

And those two items contain "PW-SKINNY" but it doesnt recognize that it's there

I can't figure out what can be the problem here!

Please Help!

catalogdebug.png (48.4 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

·
Anant Sharma avatar image
Anant Sharma answered

i found out the for loop is totally faulty. Moderators please delete this question as i can't find a way to delete it

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.