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 /
  • API and SDK Questions /
avatar image
Question by Charles McGregor · Mar 02, 2020 at 03:55 PM · unity3dLeaderboards and Statisticslimits

How do you get total number of entries in a Leaderboard?

I'm looking to grab the total number of entries a leaderboard has so I can use that number for other features in my game. I'm not looking for the data from all of the entries at once, just the total number of them. I want to have a feature that lets you know if you are in the "Top 50%" or "Top 25%" and so on in a leaderboard to give you some context to how well you did. I also am breaking up the amount of entries shown on the screen into pages and I want to show how many pages there are (ex: Page 12 of 342).

If I can only get a ballpark estimate of how many there are would work ok as well. If there was actually 4,384 entries, but it estimates 4,000 or 5,000 entries that would be fine. I'm trying to let the player know roughly where they land in terms of all other players at least. I also know that things aren't precise after 1,000 entries so if it isn't possible to have more pages than the 1,000 entries allow or I even have to get rid of the concept of pages that is ok as well, just trying to see if it is possible.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Citrus Yan · Mar 03, 2020 at 05:46 AM

Currently PlayFab does not provide such API to do the work directly. However, since Leadboards are based on Statistics, hence we can count the amount of a specific Statistic type possessed by players to estimate the total number of entries in a Leaderboard, here is a workaround you can consider:

  1. Let’s suppose we want to count the number of entries in a Leaderboard for Statistic s, and, the values set for s are greater than 0.
  2. Create a segment for players whose values of Statistic s are great than 0, this will exclude those players who haven’t got into the Leaderboard yet, which gives an estimate number of entries for this Leaderboard:

  3. Call Server/GetPlayersInSegment API to page through all players in that newly created segment, of course we don’t want to actually parse through all the players, instead, what we really want the ProfilesInSegment property which indicates the amount of players in that segment returned from the API call, in other words, the estimate number of total entries for the aforementioned Leaderboard. Therefore, here is sample request:
{

  "SegmentId":
"id_of_the_newly_created_segment", //segmentId can be retrieved using
Server/GetAllSegments

  "MaxBatchSize": 1, //minimum value
to be set, this intends to reduce the overhead cost on the PlayFab service

  "SecondsToLive":1 //minimum value
to be set, this intends to reduce the overhead cost on the PlayFab service

}

Please also note that the GetPlayersInSegment API is limited to being called 30 times in one minute. You will be returned an error if you exceed this threshold. Therefore, it’s suggested that you cache the value of the total number in Title Data or something similar, for instance, a database hosted by yourself.

segconfig.png (6.6 kB)
Comment

People who like this

0 Show 4 · 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 Charles McGregor · Mar 03, 2020 at 11:55 AM 0
Share

Ah ok, this seems like a nice workaround, thanks for the suggestion! Though I do have a question on accessing that server data in a secure way from Unity. I'm pretty new to the PlayFab workflow and I don't know how to access those server API calls safely. Would this be where CloudScripts would come in?

avatar image Citrus Yan Charles McGregor · Mar 04, 2020 at 09:26 AM 0
Share

You cannot directly call server APIs from the client-side, that's for sure. You'll need to access those server APIs from the server-side, either through your own hosted servers, or CloudScript. CloudScript enables you to build server-side logic and functionality that scales to meet your demand, without worrying about servers or infrastructure, please navigate to this doc for more info: https://docs.microsoft.com/en-us/gaming/playfab/features/automation/cloudscript/

avatar image Charles McGregor Citrus Yan · Mar 05, 2020 at 08:22 PM 0
Share

Ah ok, gotcha. Thanks so much for the clarification!

Show more comments
avatar image

Answer by smumair06 · Jun 17 at 03:34 AM

Still we don't have such API or is it available now ?

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

    3 People are following this question.

    avatar image avatar image avatar image

    Related Questions

    Unity3d,trying to make a leaderboard,show up the statistics in UI.text,Unity3d ,trying to make leaderboard statics appear on UI.text 2 Answers

    Wrong country being reported. 1 Answer

    How to update username, email and password? 1 Answer

    Can we do action when Leaderboard is reset? 1 Answer

    How to get score of a user on any specific leaderboard 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