question

josejorgejoao3 avatar image
josejorgejoao3 asked

ExecuteCloudScript FunctionResult: null

I added this script to my CloudScript:

handlers.getCurrentTime = function ()
{ 
var now = new Date();
return now.getTime() / 1000;
}

I tested a sample request to my function in this page

https://api.playfab.com/Documentation/Client/method/ExecuteCloudScript

And the API Call results prints everything just fine. But when I call the function on my game I get this in return:

{"FunctionName":"getCurrentTime","Revision":5,"FunctionResult":null,"Logs":[],"ExecutionTimeSeconds":9.21E-05,"MemoryConsumedBytes":1168,"APIRequestsIssued":0,"HttpRequestsIssued":0,"Error":null,"Request":{"FunctionName":"getCurrentTime","FunctionParameter":null,"RevisionSelection":null,"SpecificRevision":null,"GeneratePlayStreamEvent":true},"CustomData":null}

I don't know why the FunctionResult is null :S Here is the function I'm calling:

public void StartCloudGetCurrentTime()
{
ExecuteCloudScriptRequest request = new ExecuteCloudScriptRequest()
{
FunctionName = "getCurrentTime", 
GeneratePlayStreamEvent = true,
};
PlayFabClientAPI.ExecuteCloudScript(request, OnCloudGetCurrentTime, OnErrorShared);
}

Thanks for your time :D

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.

Joshua Strunk avatar image
Joshua Strunk answered

I could be incorrect but I could of sworn you need to wrap single literal values returned from CloudScript into at least a basic JSON object.

return now.getTime() / 1000;

Would become

return {


 result: now.getTime() / 1000

};

edit: Fixed bug in my code snippet silly semi colon in JSON object

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

josejorgejoao3 avatar image josejorgejoao3 commented ·

Thank you for your reply. I answered you with a big and detailed answer but I don't know what happened so I'm just going to say that I tried using those lines to my script but it is throwing a sintax error. Though I don't think that is the problem.

1 Like 1 ·
josejorgejoao3 avatar image josejorgejoao3 commented ·

Thank you for the reply. I tried that but it didn't work due this syntax error:

SyntaxError: Unexpected token ; at Script Document [3]:36:31 -> result: now.getTime() / 1000;

I don't know if that is the problem since I can Debug.Log all the information of the call with this code:

private static void OnCloudGetCurrentTime(ExecuteCloudScriptResult result)
{
	Debug.Log(PlayFab.Json.JsonWrapper.SerializeObject(result));
	Debug.Log(PlayFab.Json.JsonWrapper.SerializeObject(result.FunctionResult));
}

I'm new to PlayFab and all this, so sorry if I'm saying something wrong.

1 Like 1 ·
Joshua Strunk avatar image Joshua Strunk josejorgejoao3 commented ·

Completely my bad did not even think twice about copying the semi colon into the JSON object but it was not suppose to be there. I have edited my original post to fix the syntax error.

1 Like 1 ·
josejorgejoao3 avatar image josejorgejoao3 Joshua Strunk commented ·

Thanks! That did work! It's now returning:

"FunctionResult": { "result": 1474473319.597 }

The thing is that my goal was to get:

"FunctionResult": 1474473319.597

Is there a way I can do that?

1 Like 1 ·
Show more comments
Show more comments
brendan avatar image
brendan answered

Actually, that handler works just fine when I test it:

{
    "code": 200,
    "status": "OK",
    "data": {
        "FunctionName": "getCurrentTime",
        "Revision": 320,
        "FunctionResult": 1474406462.287,
        "Logs": [],
        "ExecutionTimeSeconds": 0.0004944,
        "ProcessorTimeSeconds": 0,
        "MemoryConsumedBytes": 12960,
        "APIRequestsIssued": 0,
        "HttpRequestsIssued": 0
    }
}

What is your title ID, @josejorgejoao3?

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

josejorgejoao3 avatar image josejorgejoao3 commented ·

Thank you for replying Brendan. My title Id is C904, why? I believe it is set correctly since I'm getting the PlayStream Events.

0 Likes 0 ·
brendan avatar image brendan josejorgejoao3 commented ·

Because that allows me to run the handler in your title directly, and check the logs. I just ran that handler (getCurrentTime) on your PlayFab ID 61AAB3C20273970, and it worked fine:

{
    "FunctionResult": 1474410423.306,
    "Logs": [],
    "ExecutionTimeSeconds": 0.0007473,
    "MemoryConsumedBytes": 12928,
    "APIRequestsIssued": 0,
    "HttpRequestsIssued": 0,
    "Error": null
}

Can you try calling it in the Game Manager (https://developer.playfab.com/en-us/C904/players/61AAB3C20273970/cloudscript) and Postman, to see what results you get?

0 Likes 0 ·
josejorgejoao3 avatar image josejorgejoao3 brendan commented ·

Sure, here it is:

{
    "FunctionResult": 1474473632.194,
    "Logs": [],
    "ExecutionTimeSeconds": 0.0008985,
    "MemoryConsumedBytes": 12928,
    "APIRequestsIssued": 0,
    "HttpRequestsIssued": 0,
    "Error": null
}

Everything is just fine. What can I be doing wrong?

0 Likes 0 ·
Show more comments
Show more comments
josejorgejoao3 avatar image josejorgejoao3 commented ·

Oh sorry, here is my OnCloudGetTime function:

private static void OnCloudGetCurrentTime(ExecuteCloudScriptResult result)
{
		Debug.Log(PlayFab.Json.JsonWrapper.SerializeObject(result));
		Debug.Log(PlayFab.Json.JsonWrapper.SerializeObject(result.FunctionResult));
}

Is anything wrong or missing?

0 Likes 0 ·
brendan avatar image brendan josejorgejoao3 commented ·

No, the issue is that our SDK isn't properly getting you the value if it's a simple int. I've opened a bug on this with our tools team to get this fixed in the SDK. For now you would need to use the method Joshua recommended, and return it as ab object.

0 Likes 0 ·
Gilbert Villanueva avatar image Gilbert Villanueva commented ·

@Brendan - I am seeing the same problem also. I can see the function result in Game Manager but it is null when calling it in my C# code. I tried adding the result key as mentioned in the post with no luck.

Here is the result via Game Manager. The title is 62BAD. Function is cosumeItem

{
    "FunctionResult": {
        "result": {
            "Success": true,
            "RemainingUses": 0
        }
    },
    "Logs": [
    ],
    "ExecutionTimeSeconds": 0.0620735,
    "MemoryConsumedBytes": 48672,
    "APIRequestsIssued": 2,
    "HttpRequestsIssued": 0,
    "Error": null
}
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.