question

mr22120237 avatar image
mr22120237 asked

UpdateUserInventoryCustomData function not found in cloud script

HI,

I am new to playfab, and I have been confuse by updating a instance item's value(Level) to user about 2days....I really need some help

My request is simple. Item has it's own level for each player that they can upgrade item level by gold.

However, I tried to call [server.UpdateUserInventoryCustomData] this function but it seems not exist...(see the picture)


Is it correct ?

Because I try to set a {Lv : 0} custom data to by GrantItem to new player, but it just not work.

question.jpg (8.7 KiB)
question-2.jpg (13.7 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

·
Citrus Yan avatar image
Citrus Yan answered

Please try the following code snippet:

handlers.test1 = function (args, context){
    
    var result = server.GrantItemsToUser({PlayFabId : currentPlayerId, ItemIds: ["your_item_id"]});
    log.info (JSON.stringify(result))
    server.UpdateUserInventoryItemCustomData({PlayFabId : currentPlayerId, ItemInstanceId: result.ItemGrantResults[0].ItemInstanceId, Data: {Lv: "0"}})


}

And, please make sure that the item id you passed to GrantItemsToUser is defined in the Catalogs (default catalog in this case), else it would return the following response, where ItemInstanceId is not present since that specific item does not exist :

 "data": {
        "ItemGrantResults": [
            {
                "PlayFabId": "B564478C7D3B3709",
                "Result": false,
                "ItemId": "not_defined_item",
                "UnitPrice": 0
            }
        ]
    }
1 comment
10 |1200

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

mr22120237 avatar image mr22120237 commented ·

Thanks for replying first.

Your test1 function works perfectly.

After I try to move out the method like picture below , it works too.

Thanks you very much!

Btw , sorry for a newbie question : where can I get the "data" result (your second paste) ?

0 Likes 0 ·
1.jpg (62.4 KiB)

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.