question

yurimarua avatar image
yurimarua asked

Update Item Custom Data

I'm trying to add an item to the player's inventory and right after updating the custom data, the item goes into the player's inventory but not with the custom data, what am i doing wrong?

CLOUD SCRIPT

handlers.additem = function(args){ var result = server.GrantItemsToUser( { PlayFabID: currentPlayerId, CatalogVersion : "Equipamentos", ItemIds : "EspadadeFerro" });

var results = result.ItemGrantResults; var instId = results.ItemInstanceId;

server.UpdateUserInventoryItemCustomData ({ PlayFabId: currentPlayerId, ItemInstanceId: instId, Data: {AtaqueFisico : args.DanoFisico} }); };

UNITY C#

public void addItem01()

{ PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest() { FunctionName = "additem", FunctionParameter = new { DanoFisico = 33 }, }, OnCloudAddItem01, OnErrorShared); } private static void OnCloudAddItem01(ExecuteCloudScriptResult result) { Debug.Log(PlayFabSimpleJson.SerializeObject(result.FunctionResult)); JsonObject jsonResult = (JsonObject)result.FunctionResult; object messageValue; jsonResult.TryGetValue("messageValue", out messageValue); Debug.Log((string)messageValue); } private static void OnErrorShared(PlayFabError error) { Debug.Log(error.GenerateErrorReport()); }

CloudScript
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

The result returned by GrantItemsToUser is an array: https://docs.microsoft.com/zh-cn/rest/api/playfab/server/player-item-management/grantitemstouser?view=playfab-rest#grantitemstouserresult. Therefore, you’ll need to use indexes to access the previously granted item, like this:

var instId = results[0].ItemInstanceId
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.

yurimarua avatar image yurimarua commented ·

Thank you, i forgot to use the index

0 Likes 0 ·

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.