Prerequisites
To follow this tutorial, you need:- A PlayFab account. If you don’t have one, you can create it here.
- An Azure subscription. If you don’t have one, you can create it here.
Create a leaderboard using Azure Functions
In this section, we’re going to create a leaderboard that allows you to submit scores and retrieve the top scores.- This function attribute
[Function("LeaderboardExample")]defines the name of the function, in this caseLeaderboardExample. - The function is triggered by an HTTP request, as indicated by the
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")]attribute. This means that the function can be accessed via HTTP GET and POST methods without any authentication. - Within the function, we set the PlayFab Title ID and Developer Secret Key to authenticate our requests to PlayFab services. You can change the way you want to access these values based on what fits best for your particular case and security requirements.
- The function checks if the query parameter “leaderboardName” is provided in the request.
- Then we call the method
LoginAsTitleEntityto authenticate as a title entity, which is necessary to create leaderboard definitions. - Finally, we call the method
CreateLeaderboardDefinitionAsyncto create a leaderboard definition with the provided name. To find more about creation of leaderboard, you can check Create basic leaderboard and Doing more with leaderboards.
