question

orbitgamesmanagement avatar image
orbitgamesmanagement asked

Update item instance custom data

I want to change and evenutally create (if it doesn't exist) an item instance custom data. I didnt found much except for this: UpdateUserInventoryItemCustomData but since i'm quite new at using CloudScript I don't really know how to make a function that given and ItemInstanceId, the name of the parameter and its value is able to update it.

Here I have this function that tries to move an item to a different kind of inventory (Player inventory, vehicle inventory etc..)

public void MoveItemToInventory(string _itemInstanceId, InventoryId _inventoryId)
{
        string playfabId = "";
        GetAccountInfoRequest request1 = new GetAccountInfoRequest();
        PlayFabClientAPI.GetAccountInfo(request1, result => { playfabId = result.AccountInfo.PlayFabId; }, OnError);


        var request = new ExecuteCloudScriptRequest
        {
            FunctionName = "UpdateItemInstanceCustomData",
            FunctionParameter = new {
                PlayFabId = playfabId,
                ItemInstance = _itemInstanceId,
                NewValue = ((int)_inventoryId).ToString(),
                ToUpgrade = "InventoryId"
            },
        };
        PlayFabClientAPI.ExecuteCloudScript(request, result => { Debug.LogError(result.FunctionResult); }, OnError);
        
        
    }

This should call this function on the Cloud similar to one I found in an old question

handlers.UpdateItemInstanceCustomData = function (args)
{
    var itemInstance = args.ItemInstance;
    var newValue = args.NewValue;
    var playfabId = args.PlayFabId;
    
    var dataPayload = {};
    var keyString = args.ToUpgrade //"SlotNumber";
    dataPayload[keyString] = newValue;
    
    var itemCustomData = server.UpdateUserInventoryItemCustomData(
    {
        PlayFabId : playfabId,
        ItemInstanceId : itemInstance,
        Data : dataPayload
    });


    return("Updated");
}

So far, I'm just getting Null as a result of the ExecuteCloudScript call and no updates

unity3dCloudScriptCustom Game Servers
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

·
Gosen Gao avatar image
Gosen Gao answered

I have tested your Cloud Script code and it works fine. If you are getting Null as a result, then there should be an error in Cloud Script. Please check the error logs to know the cause. You can check the error logs in the ExecuteCloudScript’s response or in the Data Explorer. And we also recommend to use Postman for troubleshooting.

BTW, I have noticed that the type of “_inventoryId” is “InventoryId”, while the parameter “ItemInstanceId” for UpdateUserInventoryItemCustomData should be a string, not sure if this is the cause.

3 comments
10 |1200

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

orbitgamesmanagement avatar image orbitgamesmanagement commented ·

InventoryId and ItemInstanceId are passed as strings.

This is the error message in the ExecuteCloudScriptResponse:

The script called a PlayFab API, which returned an error. See the Error logs for details.


While this is what I get on playfab
immagine-2022-07-04-232538111.png

0 Likes 0 ·
Gosen Gao avatar image Gosen Gao orbitgamesmanagement commented ·

Besides "Error", the ExecuteCloudScriptResponse should also have key "Logs", where you can get the detailed error logs.

0 Likes 0 ·
orbitgamesmanagement avatar image orbitgamesmanagement Gosen Gao commented ·

Thanks, from the logs I noticed that the problem was that the playfabId wasnt being saved correctly on client side after the GetAccountInfo request.

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.