question

Alen Jose avatar image
Alen Jose asked

Json related query

Hi,

So I have a cloud script with this function:

handlers.SelectEvent=function SelectEvent(args, context)

{ var message = "2" + currentPlayerId + "!";

log.info(message); var inputValue = null; if (args && args.inputValue) inputValue = args.inputValue;

log.debug("helloWorld:", { input: args.inputValue }); return { messageValue: message };

}

and in Unity C# I have:

public void startCloudScript () { PlayFabClientAPI.ExecuteCloudScript (new PlayFab.ClientModels.ExecuteCloudScriptRequest () { FunctionName = "helloWorld", FunctionParameter = null, GeneratePlayStreamEvent = false }, OncloudEvent, Error) ; }

for starting the function execution and:

void OncloudEvent (PlayFab.ClientModels.ExecuteCloudScriptResult res)

{

Debug.Log (res.FunctionName);

Debug.Log( PlayFab.Json.PlayFabSimpleJson.SerializeObject (res.FunctionResult));

}

for getting the result.

The issue I have is that even though I can get the function name from the first Debug statement in OnCloudEvent(), the second statement always returns null.

I want to be able to see the message that I have sent from the CloudScript.

How would I go about this?

unity3dCloudScript
10 |1200

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

Alen Jose avatar image
Alen Jose answered

i just remove :

log.info(message); var inputValue = null; if (args && args.inputValue) inputValue = args.inputValue;

log.debug("helloWorld:", { input: args.inputValue }); return { messageValue: message };

from the cloudscript and it worked

10 |1200

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

Citrus Yan avatar image
Citrus Yan answered

The FunctionName is "helloWorld" in your C# code, however, the one in your CloudScript is "SelectEvent". Generally, you'll get a response similar to the following if you provide the wrong function name which does not exist in CloudScript:

{
    "code": 200,
    "status": "OK",
    "data": {
        "FunctionName": "xxx",
        "Revision": 89,
        "Logs": [],
        "ExecutionTimeSeconds": 0.00017099999999999998,
        "ProcessorTimeSeconds": 0.0,
        "MemoryConsumedBytes": 3304,
        "APIRequestsIssued": 0,
        "HttpRequestsIssued": 0,
        "Error": {
            "Error": "CloudScriptNotFound",
            "Message": "No function named xxx was found to execute",
            "StackTrace": ""
        }
    }
}

Which I think explains why you received null from res.FunctionResult because in this case, that field doesn't exist at all. Would you please check your code again?

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.

Alen Jose avatar image Alen Jose commented ·

Ah, I'm sorry both are actually named SelectEvent. I can get the name of the function in the debug statement but not the result.

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Alen Jose commented ·

Would you please use

Debug.Log(PlayFab.Json.PlayFabSimpleJson.SerializeObject(res));

to inspect the complete result?

0 Likes 0 ·
Alen Jose avatar image Alen Jose Citrus Yan commented ·

This is the error that I get:

{"APIRequestsIssued":0,"Error":{"Error":"JavascriptException","Message":"JavascriptException","StackTrace":"TypeError: Cannot read property 'inputValue' of null\n at handlers.helloWorld (58578-main.js:50:44)\n

0 Likes 0 ·
Show more comments
Alen Jose avatar image
Alen Jose answered

@Citrus Yan any further advice?

10 |1200

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

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.