Hi there,
I am working on a UWP Windows 10 app.
To prevent cheating, I look to count points, by adding a cloudscript.
So far it works (I see in the PlayScreen Monitor) but I am struggling with the handling of the result:
private static void StartCloudHelloWorld() { var test = PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest() { FunctionName = "ResetPlayerStats", FunctionParameter = new { high = 777 }, GeneratePlayStreamEvent = true, }); OnCloudHelloWorld(test.Result.Result); } public static void OnCloudHelloWorld(ExecuteCloudScript result) { string msg = (JsonWrapper.SerializeObject(result.FunctionResult)); JsonObject js = (JsonObject)result.FunctionResult; object mmV; js.TryGetValue("mmV", out mmV); } <br>
The first parts works, and I see the points are updated but when it come to
OnCloudHelloWorld(test.Result.Result) the app shuts down.
I fear there is something with my code, but don't see where.
Hopefully anyone can help me out.
Many thanks in advance,
Michael
Answer by Marcus Nixon · May 31, 2019 at 03:13 PM
Apologies for the delay. I got this working for you but never posted it. If you are still having issues, you can take a look at my code.
public MainPage() { this.InitializeComponent(); PlayFabSettings.TitleId = "XXXX"; ExecuteAsyncTasks(); } private static async void ExecuteAsyncTasks() { await Authenticate(); await StartCloudHelloWorld().ContinueWith(executeCloudScriptResult => OnCloudHelloWorld(executeCloudScriptResult.Result.Result)); } private static async Task Authenticate() { var loginWithPlayFabRequest = new LoginWithPlayFabRequest() { Username = "XXXX", Password = "XXXX" }; await PlayFabClientAPI.LoginWithPlayFabAsync(loginWithPlayFabRequest); } private static async Task<PlayFabResult<ExecuteCloudScriptResult>> StartCloudHelloWorld() { var executeCloudScriptRequest = new ExecuteCloudScriptRequest() { FunctionName = "ResetPlayerStats", FunctionParameter = new { high = 777 }, GeneratePlayStreamEvent = true, }; return await PlayFabClientAPI.ExecuteCloudScriptAsync(executeCloudScriptRequest); } public static void OnCloudHelloWorld(ExecuteCloudScriptResult result) { string msg = (JsonWrapper.SerializeObject(result.FunctionResult)); JsonObject js = (JsonObject)result.FunctionResult; object messageValue; js.TryGetValue("messageValue", out messageValue); }
Answer by Marcus Nixon · Apr 30, 2019 at 02:41 PM
Hi Michael,
Could you please post the cloud script function that you are calling? Also, what game engine/sdk are you using to build this UWP app?
Hi @Marcus Nixon,
many thanks for the quick reply.
I am using Visual Studio 2017, with PlayFabAllSdk, v1.49.190424.
So, I don't use any engine eg Unity.
My cloud script is the following:
handlers.ResetPlayerStats = function (args, context) { var request = { PlayFabId: currentPlayerId, Statistics: [{ StatisticName: "highScore", // is the name of my Leaderboard, which should be updated Value: args.high }] }; var playerStatResult = server.UpdatePlayerStatistics(request); }; Thanks for your help!!! Best wishes, Michael
Answer by Marcus Nixon · May 01, 2019 at 06:59 PM
Hi Michael,
It looks like your OnCloudHelloWorld function is expecting a result from your cloud script function, but your cloud script function does not have a return value. I was unable to compile your code exactly as you posted, but after making some changes, I did see an unhandled exception inside your OnCloudHelloWorld function.
Hi there,
thanks for the hint.
I've changed the Code slightly to get the Code working.
But I still receive an error "Aggregate exception".
I changed the lines into
txtDebug.Text = test8.Result.Result.ToString();
just to receive a message back.
Does anybody know how to solve this?
Many thanks,
Michael
I am not sure which lines of code you have changed. Can you post your new cloud script code and C# code so that I am not making any assumptions.
Answer by michaelbb · May 23, 2019 at 01:38 AM
Hi there,
I've added the following in my CloudScript and it now looks like this:
/ This is a simple example of making a PlayFab server API call handlers.ResetPlayerStats = function (args, context) { var request = { PlayFabId: currentPlayerId, Statistics: [{ StatisticName: "highScore", Value: args.high }] }; // The pre-defined "server" object has functions corresponding to each PlayFab server API // (https://api.playfab.com/Documentation/Server). It is automatically // authenticated as your title and handles all communication with // the PlayFab API, so you don't have to write extra code to issue HTTP requests. var playerStatResult = server.UpdatePlayerStatistics(request); return {messageValue: "Cloud Updated"}; };
Unfortunately I am still struggling as the app brokes down after the CloudScript had been executed.
What's curious is that I can see in Playstream monitor that it's been successfully executed.
I just want to achieve that I get a message back, so that I can display the user, everything had been fine or not.
I appreciate any further hints.
Many thanks in advance,
best wishes Michael
Answer by michaelbb · May 31, 2019 at 09:45 PM
many thanks for your answer. Now it's working as expected.
Enjoy your weekend,
best wishes,
Michael
Cloudscript Limit 1 Answer
Photon Webhook url config 1 Answer
How to deserialize a cloudscript server call back to the client? 2 Answers
Cloudscript limits? | Can I link two frictionless logins? 1 Answer
Http request call timeouts 1 Answer