question

michaelbb avatar image
michaelbb asked

CloudScript Windows10

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

CloudScriptwindows
10 |1200

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

Marcus Nixon avatar image
Marcus Nixon answered

@michaelbb

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);
}

10 |1200

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

Marcus Nixon avatar image
Marcus Nixon answered

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?

1 comment
10 |1200

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

michaelbb avatar image michaelbb commented ·

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
0 Likes 0 ·
Marcus Nixon avatar image
Marcus Nixon answered

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.

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

michaelbb avatar image michaelbb commented ·

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

0 Likes 0 ·
Marcus Nixon avatar image Marcus Nixon michaelbb commented ·

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.

0 Likes 0 ·
michaelbb avatar image
michaelbb answered

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

10 |1200

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

michaelbb avatar image
michaelbb answered

Hi @Marcus Nixon

many thanks for your answer. Now it's working as expected.

Enjoy your weekend,

best wishes,

Michael

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.