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?
Answer by Citrus Yan · Apr 02, 2020 at 06:02 AM
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?
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.
Would you please use
Debug.Log(PlayFab.Json.PlayFabSimpleJson.SerializeObject(res));
to inspect the complete result?
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