question

oskar avatar image
oskar asked

FunctionResult missing from ExecuteCloudScriptResult

I'm pulling my hair over this issue. I'm trying out Unity with PlayFab for the first time and can't even get the simplest "hello world" type cloud script call to work. Whatever I do the response comes back without FunctionResult in it. I do however get all the other data like ExecutionTimeSeconds, Revision and whatnot.

Calling the cloudscript handler/function from game manager works. Then FunctionResult is included in the response but from within Unity it isn't. I've also tried both returning a naked string as well as wrap it in a json. Same outcome.

I can see here in the forums that people have had similar issues in the past but that was ages ago and I've also made sure I'm not making any of the mistakes pointed out in those old threads.

Can you please advise? My title id is 1D80.

Thanks

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

oskar avatar image oskar commented ·
PlayFabCloudScriptAPI.ExecuteEntityCloudScript(new ExecuteEntityCloudScriptRequest()
            {
                Entity = new PlayFab.CloudScriptModels.EntityKey { Id = entityId, Type = entityType },
                FunctionName = "Hello",
                RevisionSelection = CloudScriptRevisionOption.Latest


            }, OnPlayFabEntityCloudScriptExecuted, OnPlayFabError/*, customData, extraHeaders*/);

0 Likes 0 ·
oskar avatar image oskar commented ·
handlers.Hello = function(args, context) {
    log.debug("Hello called!");
    var response = {"msg": "OH CMON!"};
    return response;
}

0 Likes 0 ·
oskar avatar image
oskar answered

There is this caveat that if using the standard C# JsonUtility the FunctionResult won't be recognized. You have to use PlayFabs PlayFabSimpleJson to be able to log the result.

Debug.Log(JsonUtility.ToJson(result.FunctionResult)); // =>> {}
Debug.Log(PlayFabSimpleJson.SerializeObject(result.FunctionResult)); // =>> prints the response object properly 
10 |1200

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

Sarah Zhang avatar image
Sarah Zhang answered

Your CloudScript function has run successfully, and you have got the function result. You can navigate to [GameManager]->[Data]->[Event History], use the [Show JSON] button (arrow icon on the item’s left) to expand the details of items [player_executed_cloudscript SUCCESS: Hello() (revision xx)], you will find the function result in their JSON. So, API and your process work fine. It looks like the problem is in the Unity’s client code, you can try to refer to the doc Writing custom CloudScript to modify it.

In addition, you can use ExecuteCloudScript instead of ExecuteEntityCloudScript in your code. ExecuteEntityCloudScript should be used when you want to execute Entity API on Cloud Script. Executing “Hello” function doesn’t need to use it.

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.

oskar avatar image oskar commented ·

I realize I wouldn't need to use ExecuteEntityCloudScript for this simple cloudscript function but my aim is to eventually make use of Entity Api so this was just a first little step where I unfortunately ran into problems right away.

You're right tho that the issue was in my client code. By using the code at the bottom I can get a hold of the returned value. Very frustrating tho that when just logging the full result of the cloudscript function with

Debug.Log(JsonUtility.ToJson(result.FunctionResult)); // =>> {}

the sdk treats it as if the FunctionResult just isn't there. Very un-intuitive.

private static void OnCloudHello(ExecuteCloudScriptResult result)
    { 
        Debug.Log(PlayFabSimpleJson.SerializeObject(result.FunctionResult));
        JsonObject jsonResult = (JsonObject)result.FunctionResult;
        object responseMessage;
        jsonResult.TryGetValue("msg", out responseMessage);
        Debug.Log((string)responseMessage);
    }

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.