- Learn more about the Entity Programming Model here: Entity Programming Model.
- Check out how groups work here: Groups.
Creating a leaderboard
Depending on the game and the type of scenarios that you’re going have, you’re most likely going to create multiple leaderboards. In this particular context, we want to show to different scenarios for this game and how to use the service to address each of them.Players leaderboards
On this example, we have players that are terraforming planets and they’re gaining experience points by doing certain actions in the game. So we’re going to have a leaderboard for tracking that experience at the player level. This process follows the same behavior as it was presented on other tutorials like the Create basic leaderboard. Now the key aspect here is that EntityType parameter needs to be"title_player_account" so it going to be only for players.
Group leaderboards
Now let’s go into the aspect of the game that was given in the example, alliances. So we can create alliances in PlayFab by using the"group" entity. This group entity allows us to have a structure for which player can join, it also has roles and other interesting features that
empower this type of scenarios in games. For the creation of the leaderboard we need to have to two things clear.
- The EntityType parameter needs to be
"group". - This leaderboard is independent. So adding a score for an alliance is manual process separated from the players leaderboard. This behavior allows different ways in which the scores are related to the players or it could be a new metric only applicable for groups.
Adding data to the leaderboard
After we created both leaderboards, we need to see how can we add data to them. Now as it was mentioned before in the previous example, these leaderboards are independent of each other; which gives the developer the control of applying custom logic on how scores work for alliances (groups).EntityId to the service. If you have a leaderboard of players
the entities are "title_player_account" if the leaderboard is composed by groups then you need to provide entities that are "group.
Retrieve data from the leaderboard
Now, to get the data of the leaderboard we have all the options described in here Doing more with leaderboards except for the GetFriendLeaderboard API.Display name for groups leaderboards
Finally, another detail that we can do with group leaderboards is to set the display name with the group name of the entity. So if you have an alliance called: “Raiders”, this group name is going to be map to the entity with theDisplayName property.
CreateGroupAsync method. The first step of this execution is to return the Group object,
which we’re going to use for setting the display name. We do this process by mapping the group name to the entity by using the
SetDisplayNameRequest object and then executing the PlayFabProfilesAPI.SetDisplayNameAsync method.
Conclusions
In this tutorial, we learned how to do the following operations:- Create a group leaderboard.
- Learn how to feed data to that leaderboard.
- Retrieve the leaderboard.
- Change the displayName so it can show the group name.
