question

Byakuya avatar image
Byakuya asked

How Update statistics player data using AzureFunction ?

Hi, I've been blogging about this topic for several days now.

Developing a game on Unity, I would like to update the player's statistics using an Azure function. I have already created a function in Unity that sends a Get to Azure with parameters in the URL and Azure returns the values well.

I also created a script to update the player statistics, the problem is that you have to check "Allow client To post player statistics" which can lead to cheat. I would like to reproduce this script on Azure with Azure Function but it does not support the Playfab API and I have no idea how to proceed.

Could you help me on this subject or give me an idea if I'm not at all on the right way ?

Player DataLeaderboards and Statisticsdata
azure-function.png (34.7 KiB)
capture.png (40.9 KiB)
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.

Byakuya avatar image Byakuya commented ·

I forgot this code ( it's the code to update the statistics when the box is checked ) and this is the one I would like to run in Azure Function.

1 Like 1 ·
Made Wang avatar image
Made Wang answered

Is your postRequest coroutine used to call Azure Function? If so, in fact, you can use ExecuteFunction to call a registered Azure Function, refer to PlayFab CloudScript using Azure Functions Quickstart Guide - PlayFab | Microsoft Docs to learn more.

Secondly, have you followed the documentation mentioned above to configure some necessary environment to call PlayFab API on Azure Function? If already configured, then you need to reference some necessary namespaces, such as:

using PlayFab; 

using PlayFab.Samples;

and other you may need:

using PlayFab.ServerModels;

In addition, on the Azure Function you can use the server-side API, such as calling UpdatePlayerStatistics to update the statistics, which is more secure.

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

Byakuya avatar image Byakuya commented ·

Thank you for your answer, I have indeed followed your instructions and it has unblocked me in several places.

However, I still have a problem: in Unity, my terminal displays: "No function named UpdatePlayerStatistic was found To execute".

My code to query the server :

My code on my azure server :

I specify that the packages "PlayFabAllSDK" and "PlayFabCloudScriptPlugin" are well installed and that my local.settings.json file contains the Key and Title ID. I tried with and without "FunctionParameter" in both cases it does not work. My function is registered in Automation of Playfab with the right name and url.

I also wondered if this was due to the fact that I did not add the namespace "CS2AFHelperClasses.cs" but I do not understand how this could work knowing that this file will not be deployed on my Azure server and therefore not recognized once my function is deployed.

If you could give me a guideline, thanks in advance.

1 Like 1 ·
clientcode.png (26.5 KiB)
serverscript.png (26.8 KiB)
Made Wang avatar image Made Wang Byakuya commented ·

Judging from the error message, the error is likely to occur in registering Azure Function. For further troubleshooting, you can refer to Local debugging for Cloudscript using Azure Functions - PlayFab | Microsoft Docs to try local debugging.

In addition, PlayFabCloudScriptPlugin is outdated, you don't need to install it, and CS2AFHelperClasses is used to replace it, you should put it in your Azure Function directory for use, and it will be packaged and uploaded together when you upload Azure Function. I recommend you to complete the HelloWorld function by referring to the above documentation to understand its purpose.

1 Like 1 ·
Byakuya avatar image Byakuya Made Wang commented ·

Thank you for these explanations that helped me a lot. I haven't succeeded yet but I am on the right track.

1 Like 1 ·
Byakuya avatar image
Byakuya answered

For those who have a problem similar to mine, I advise you to follow the instructions and links in the previous posts but also this link which allowed me to succeed in what I wanted to do.

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.