question

helloza123 avatar image
helloza123 asked

GrantItemsToUser not adding new inventory item even catalog version specified.

Hi, I've just started testing Playfab today and when I try to use GrantItemsToUser (already specify the catalog version for it), nothing are added to inventory if that item do not exist in primary catalog.

This is my code.

handlers.AddRandomEquipments = function(args, context) //not working at all
{
    var weaponTypes = ["armor","boots","gloves","helmet","weapon"];
    var weaponTier = 1;


    var randomType = Math.floor(Math.random() * weaponTypes.length);
    
    var weaponShortCode = randomType + "." + weaponTier;
    
    //This is not primary catalog
    var request = server.GrantItemsToUser({PlayFabId: currentPlayerId, ItemIds: [weaponShortCode], CatalogVersion: "weaponData"});
}


handlers.AddMonster = function(args, context) //working correctly
{

//this is primary catalog
    var monsterShortCode = args.monsterShortCode;
    var request = server.GrantItemsToUser({PlayFabId: currentPlayerId, ItemIds: [monsterShortCode], CatalogVersion: "monsterData"});
}

I want to use different catalog in order to make it easier to classify items by types that's why it's quite annoying to put all the item types in the same catalog. Are there any workaround or best practice for this?

Thank you.

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

·
helloza123 avatar image
helloza123 answered

I've solved the problem, it seem I forgot to specify the array random index to the array itself.

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.