question

chaz32621 avatar image
chaz32621 asked

Leaderboard filtering 0 stats

Currently the leaderboard returns any data and ranks all players even if they just login and do nothing more. Is there a way I can filter out stats that are 0 or a value that should not have them ranked?

This would be for unity3d. I see the option of filtering in some of the documents but cant seem to apply it when calling the leaderboard request in unity.

Only thing I can think to do is sort it with my own code and re rank all the players.

Player Dataunity3dLeaderboards and Statistics
1 comment
10 |1200

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

v-humcin avatar image v-humcin ♦ commented ·

I haven't been able to reproduce this issue so far, but I have a few questions that will hopefully shed some light on the situation.

1. Are all players test accounts that you have created yourself?

2. Are these 0 values showing in the result from API calls and also on the game manager leaderboards?

3. Are newly created players starting with values already assigned in the statistics tab when viewing a player in the game manager?

0 Likes 0 ·
brendan avatar image
brendan answered

Player accounts will only have a statistic if you specifically update that statistic for them. So if players show up on the leaderboard with a score of 0, that means that there was a call on one of the title API endpoints to set that as the player's score.

Scores of 0 will be at the bottom of the leaderboard. So "filtering" would be as simple as not showing players any score below 0 in your display.

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

chaz32621 avatar image chaz32621 commented ·

Right so I did specifically added these value to there stats. So for kills I gave all players an initial 0. My question is how can I hide the players who have 0 from the leaderboard. Wouldn't me not showing the player increment there rank and I would have missing ranks?

Would it be best to just go through each result.Leadeboard[i].statvalue and skip the values I want to hide? Or can I make a leaderboard request upfront?

0 Likes 0 ·
brendan avatar image brendan chaz32621 commented ·

Sorry, but I'm still not seeing the issue. The leaderboard returned is the list of players, starting from rank 1, with the highest scores first and the lowest scores last. If all you want to do is not show anyone with a score of 0, you would simply stop the list once you hit any player with a score of 0. Everyone below that would also, therefore, be 0. And those players have no impact whatsoever on the ranks of the players above, since the rank is ordered from first to last.

0 Likes 0 ·
chaz32621 avatar image
chaz32621 answered

Here is an example of what I am asking for.



So my player logins and gets a gold set of 0. Just to setup how my game works I go ahead and create all the stats for the player on initial login.


When the player goes to the leaderboard in game. The results.leaderboard pulls all data. So that player with gold 0 gets a position on the leaderboard. What I did to combat this is to go through and remove from the list that result.

Something like so:

 	var boardName = (result.Request as GetLeaderboardRequest).StatisticName;
                        AreLeaderboardsLoaded = true;
                        MyLeaderboardData[boardName] = result.Leaderboard;
                        for (int i = 0; i < result.Leaderboard.Count; i++)
                        {
                            if (result.Leaderboard[i].StatValue == 0)
                            {
                                result.Leaderboard.RemoveAt(i);
                                i--;
                            }

The only downfall to doing this is now when I call my UI to show the leaderboard I have to create my own iteration of the rank since I cannot use the position. Here is some code snippet.

 int rank = 1;
                offset = .20f;
                foreach (GameObject LeaderboardEntryobj in GameObject.FindGameObjectsWithTag("LeaderBoard"))
                {
                    GameObject.Destroy(LeaderboardEntryobj);
                }
                var leaderboards = GetLeaderboard(GetMyLeader);
                if (leaderboards.Count > 0)
                {

LeaderboardEntryobj.GetComponent<LeaderboardEntry>().StringRank = (rank++).ToString();

 offset += .20f;
                    }


I have left off majority of the code for simplicity.

So if I create another list and get just that player playing the game data, I cannot pull from the

leaderboard.Position because this position would show the position of the player with all the players whos gold is 0.

So what I am asking is there a way I could filter out from the leaderboard certian values that shouldnt be added to the rank?

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

brendan avatar image brendan commented ·

We seem to not be connecting, in terms of our definitions. What I'm hearing you say is that you have to remove all players with a score of 0, because their presence in the leaderboards will affect the positions of players who have non-zero scores. That is literally impossible. All players with a score of 0 will be lower in the leaderboard. They cannot affect the positions of players above them in any way. In your logic for displaying the leaderboard, if you just stop iterating when you hit the first 0 score, that would do exactly what you describe - no players with 0 scores would be shown, and they would not affect the players with non-zero scores.

If there's some other definition you're using for the player position which is unrelated to the position returned in the leaderboard, can you please clarify that?

0 Likes 0 ·
chaz32621 avatar image chaz32621 commented ·

The only issue I was having was displaying each players own stats, specifically to them. With there position's. I went ahead and added code in if the user has 0 for a stat to hide the position of the player. Make it feel like they havent been ranked yet. Even tho they have in what playfab thinks.

0 Likes 0 ·

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.