question

Talha avatar image
Talha asked

How to create a centralized Leaderboard

Hi we would like to implement a centralized leaderboard in unity.

Total desired players in leaderboard is to be 100.

first 75 players then leaderboardaorundplayer with 25 as maxresultcount

A "ME" button, when pressed takes us to the current Player's Ranking.

My understanding is that we'd have to call two leaderboards, one getleaderboard and one getleaderboard around player, and we'd have to do some calculations to check whether player's ranking is top 75 players or not

Leaderboards and Statistics
10 |1200

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

Talha avatar image
Talha answered

"Hi, if this is the case. You may need to deal with the overlapping rankings by comparing PlayFabId returned from PlayerLeaderboardEntry to remove duplicate Entries."

How do we do this? any implementation guide?

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.

Citrus Yan avatar image Citrus Yan commented ·

Hi, the basic idea is to merge PlayerLeaderboardEntry returned from GetLeaderboard and GetLeaderboardAroundPlayer into one. If the player rank is 355, you will just need to append the PlayerLeaderboardEntry returned from GetLeaderboardAroundPlayer because there is no overlapping between them. If the player rank is 75, which will cause overlapping, you will need to remove the duplicate entries. You could delete entries returned from GetLeaderboardAroundPlayer to take the player to index 0, then find the right position to append it after PlayerLeaderboardEntry returned from GetLeaderboard. For instance, when the player ranks 75, the right positon for us to append is 74(index is 73, don’t forget that index starts from 0).

0 Likes 0 ·
Talha avatar image Talha Citrus Yan commented ·

Okay. Thanks. Let me implement it, I'll post here if i get in trouble.

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Talha commented ·

Yeah, any issues let us know:)

0 Likes 0 ·
Citrus Yan avatar image
Citrus Yan answered

Hi, here is my understanding of your idea, correct me if I am wrong. You need to check if the player is top 75 so you call GetLeaderboard with 75 as MaxResultsCount and 0 as StartingPosition. If the player is in top 75, then call GetLeaderboardAroundPlayer with 25 as MaxResultsCount. However, what I don’t follow is that why you set 25 as MaxResultsCount while your total desired players in leaderboard is 100. GetLeaderboardAroundPlayer retrieves a list of ranked users for the given statistic, centered on the requested player. Let’s suppose the player is ranked 75, after calling GetLeaderboardAroundPlayer with 25 as MaxResultsCount he will get a list of ranked user ranks from 63 to 87(theoretically speaking), unable to reach total desired players, let alone when the player is ranked less than 75. Therefore, you may need to call GetLeaderboardAroundPlayer with 50 as MaxResultsCount in order to reach total desired players.

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

Talha avatar image Talha commented ·

Yes you are absolutely right. We do need to set maxresultscount to 50 to complete the leaderboard. Our main problem is that How do we solve the issue of overlapping player rankings? Like take the same example as above. If the user is at rank =75. And then we call GetLeaderboardAroundPlayer with 50 as MaxResultsCount we'll have overlapping rankings from 50 to 100 right?

How do we solve this? For Me button I guess we''ll just take the player to the GetLeaderboardAroundPlayer's index 0 to solve it.

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Talha commented ·

Hi, I have to confirm something from you before making any proper suggestions. If the player is ranked out of top 100, will the “Me” button still work for him? What I am saying is that If your Leaderboard only shows the top 100 players then you’ll just only need to use GetLeaderboard to get the top 100 players. Check if the player is within top 75, if he is, then the “Me” button works for him, if not, then disable the “Me” button for him. In this way, there is no need to call GetLeaderboardAroundPlayer and the overlapping issue won’t occur at all. Correct me if I am wrong, thanks.

0 Likes 0 ·
Talha avatar image Talha Citrus Yan commented ·

The Me button is just to get to the players position in the leaderboard. Me button is shown in all conditions. It is just to quickly traverse through the leaderboard to get to the player's rank. (whether by using GetleaderboarAroundPlayer or Getleaderbaord, this is the confuisng bit becuause we dont know how to get around it.)

0 Likes 0 ·
Show more comments
Show more comments

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.