Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • General Discussion /
avatar image
Question by michaelbb · Apr 30, 2019 at 12:30 PM · CloudScriptwindows

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

Comment

People who like this

0 Show 0
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

5 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Marcus Nixon · May 31, 2019 at 03:13 PM

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

Comment

People who like this

0 Show 0 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

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?

Comment

People who like this

0 Show 1 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image michaelbb · Apr 30, 2019 at 07:52 PM 0
Share

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
avatar image

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.

Comment

People who like this

0 Show 2 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image michaelbb · May 17, 2019 at 07:50 AM 0
Share

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

avatar image Marcus Nixon michaelbb · May 17, 2019 at 05:37 PM 0
Share

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.

avatar image

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

Comment

People who like this

0 Show 0 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by michaelbb · May 31, 2019 at 09:45 PM

Hi @Marcus Nixon

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

Enjoy your weekend,

best wishes,

Michael

Comment

People who like this

0 Show 0 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    2 People are following this question.

    avatar image avatar image

    Related Questions

    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

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges