Now from the above mentioned cloud script, how can I access the variables - keystring, datapayload or messageGroupId in my Unity's C# Script when I call the ExecuteCloudScript. I am confused about the Json concepts and I don't know anything about Java. So please help me to get through this problem. Thank you in advance.
Answer by Junjin Chen · Nov 20, 2020 at 07:06 AM
The variables of your Unity Script can be passed to CloudScript through FunctionParameter in Unity, for example:
private static void StartCloudHelloWorld(){ PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest() { FunctionName = "helloWorld", // Arbitrary function name (must exist in your uploaded cloud.js file) FunctionParameter = new { name = "YOUR NAME" }, // The parameter provided to your function GeneratePlayStreamEvent = true, // Optional - Shows this event in PlayStream }, OnCloudHelloWorld, OnErrorShared);}
Then, in CloudScript, you could use the args to access the variables, for example:
handlers.helloWorld = function (args) {
// ALWAYS validate args parameter passed in from clients (Better than we do here)
var message = "Hello " + args.name + "!"; // Utilize the name parameter sent from client
log.info(message);
return { messageValue: message };
}
Please refer to: Writing custom CloudScript
If you have any further questions, please feel free to ask.
Yeah I tried, but I am getting this error : 'ExecuteCloudScriptResult' does not contain a definition for 'message' and no accessible extension method 'message' accepting a first argument of type 'ExecuteCloudScriptResult' could be found (are you missing a using directive or an assembly reference?)
In Unity, the ‘ExecuteCloudScriptResult’ does not contain message property. Please refer to ExecuteCloudScriptResult or the SDK document to check its structure. To get the function result, you could use ‘result.FunctionResult’ in the successful callback, which is an object. There are plenty ways to parse the object in C# and get its property, an example would be:
void OnSuccess(PlayFab.ClientModels.ExecuteCloudScriptResult result)
{
Debug.Log(JsonUtility.FromJson<Hello>(result.FunctionResult.ToString()).messageValue);
}
Where the Hello Class is defined as:
public class Hello
{
public string messageValue;
}
Please I want the answer. I am getting this type of errors for the rest of the variables too
SharedGroupData Notification on Desktop 1 Answer
Can We call Cloud Scripts in Unity - void Update() for receiving a friend request ? 2 Answers
How to access the variables of cloud scripts in Unity's C# script ? 0 Answers
ExecuteCloudScript Errors - 'ExecuteCloudScriptResult' does not contain a definition 0 Answers
Cloud Script Return Value Problem - Null Reference Error 1 Answer