question

fanwu avatar image
fanwu asked

Cloudscript Question

I made a cloud script to change "custom inventory instance data".

handlers.Liwh_UpdateUserInventoryItemCustomData = function(args){
var itemId = null;
var itemOtherId = null;
    if (args && args.itemId)
        itemId = args.itemId;
    if (args && args.itemOtherId)
        itemOtherId = args.itemOtherId;
   return { messageValue: itemId };
//var result = server.UpdateUserInventoryItemCustomData({
//PlayFabId: currentPlayerId,
   //   ItemInstanceId: itemId,
   //   Data: {
   //     "UsedSkinHeroId": itemOtherId
   //   }
//});
}

Running this with "try it" on website or in player/cloud script was fine, but when I tried to run this on client, it returned ItemInstanceId = null as result.

 var request = new ExecuteCloudScriptRequest { FunctionName = _functionName, FunctionParameter = _functionParameter }; PlayFabClientAPI.ExecuteCloudScript(request, executeEntityCloudScriptResult, OnFailure); 

It seems that FunctionParameter was not correct.

FunctionParameter = "{\"itemId\": \"9DEDC1E5969AF6D7\", \"itemOtherId\": \"30001\" }" 

I do not know what I did wrong here.

PS: Btw, I always wondered how to actually "shut down server", usually there is a big red button somewhere but I must missed it completely.

10 |1200

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

Andy avatar image
Andy answered

I'm not sure I completely follow your question. It sounds like you're trying to figure out why your cloud script function parameters are not making it to your function as you expect. If that's the case, the first thing I'd recomend is changing the way you're passing in the parameters. Instead of creating an escaped JSON string, create a dynamic JSON object as illustrated in the tutorial here.

Your request code could look something like this:

PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest()
    {
        FunctionName = "Liwh_UpdateUserInventoryItemCustomData",
        FunctionParameter = new { itemId = "9DEDC1E5969AF6D7", itemOtherId = "30001" }
    }, executeEntityCloudScriptResult, OnFailure);
2 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.

fanwu avatar image fanwu commented ·

Thank you very much for the prompt response! Btw, how to shut down server again?

0 Likes 0 ·
Andy avatar image Andy ♦♦ fanwu commented ·

If you're talking about our multiplayer server hosting. You can trigger all servers to shut down by ensuring there are no builds uploaded with a region set. That means you can either delete all builds or unselect all regions on all builds.

0 Likes 0 ·
fanwu avatar image
fanwu answered

Thank you again! I tested the code you provided and it worked wonderfully in Unity client; however, when I tested this with an android build, it stopped working.

"Logs": [
            {
                "Level": "Error",
                "Message": "PlayFab API request error",
                "Data": {
                    "api": "/Server/UpdateUserInventoryItemCustomData",
                    "request": {
                        "PlayFabId": "93116910444F6D0D",
                        "ItemInstanceId": null,
                        "Data": {
                            "UsedSkinHeroId": null
                        }
                    },
                    "result": null,
                    "apiError": {
                        "code": 400,
                        "status": "BadRequest",
                        "error": "InvalidParams",
                        "errorCode": 1000,
                        "errorMessage": "Invalid input parameters",
                        "errorHash": null,
                        "errorDetails": {
                            "ItemInstanceId": [
                                "The ItemInstanceId field is required."
                            ]
                        }
                    }
                }
            }
        ],

The ItemInstanceId returned null again. I wonder if android has a different approach.

4 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.

brendan avatar image brendan commented ·

Short answer, no. The only time there's a platform difference is when that's the purpose of the API - like login with Google, or iTunes receipt validation. All the other API calls are completely platform agnostic.

Can you provide the specifics on the parameters you are passing into the call, and the Title ID/PlayFab ID you are using?

0 Likes 0 ·
fanwu avatar image fanwu brendan commented ·

Parameters:

FunctionParameter = "{\"itemId\": \"9DEDC1E5969AF6D7\", \"itemOtherId\": \"30001\" }"

TitleID:

D2FD

PlayFabID:

93116910444F6D0D

Thank you very much!

0 Likes 0 ·
brendan avatar image brendan fanwu commented ·

I'm confused. The call you stated was having the problem was UpdateUserInventoryItemCustomData, which requires the ItemInstanceId - which is not set in the data in your example. Can you re-check that?

0 Likes 0 ·
Show more comments

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.