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.
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:
{ "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 }
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?
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/
Ah ok, gotcha. Thanks so much for the clarification!