Get the Rank, Username and Score of the players around my score

58 views
Skip to first unread message

trudoe

unread,
Jun 3, 2012, 9:26:33 PM6/3/12
to moga...@googlegroups.com
I am trying to display the rank and score of rivals for a given user. Right now I am using the GetLeaderboard(..., username) and it works great! But I can't get the rank of the other user (see class Score). I want to display the rank, username and score of the players around my score. How can I do that?

   public class Score
   {
      public string UserName { get; set; }
      public int Points { get; set; }
      public string Data { get; set; }
      public DateTime Dated { get; set; }
   }

Thanks! 

Karl Seguin

unread,
Jun 3, 2012, 9:33:14 PM6/3/12
to moga...@googlegroups.com
If you know the rank of 1 player, can't you "calculate" the rank of the other players on the device itself? 

If the player "John" has a rank of 125 with a score or 100....you know that "Sam" with a score of 105 will have a rank of 124...and "Matt" with a score of 95 will have a rank of 126...

Karl

trudoe

unread,
Jun 3, 2012, 9:34:42 PM6/3/12
to moga...@googlegroups.com
I can certainly do that, but I'll have to make two calls to Mogade.

Karl Seguin

unread,
Jun 3, 2012, 9:37:31 PM6/3/12
to moga...@googlegroups.com
Ya. One day I'll redo the ranking so that it isn't such a pain...I have the solution now, it's just a matter of redoing how the leaderboards are done...one day... :)

Karl

trudoe

unread,
Jun 10, 2012, 9:40:03 PM6/10/12
to moga...@googlegroups.com
Are the score 0-based or 1-based? It seems like depending on the scope I am getting 0-based values and sometime 1-based value. I am probably doing something wrong, but I just want to check.

Martin

Karl Seguin

unread,
Jun 11, 2012, 11:45:27 AM6/11/12
to moga...@googlegroups.com
Do you mean the ranks? they should be 1-based...where/when are you getting 0 base ranks ?

Karl

trudoe

unread,
Jun 13, 2012, 8:31:29 PM6/13/12
to moga...@googlegroups.com
I am seeing that behavior when I call the GetRank API with the Overall scope. Essentially, I call GetLeaderboard to get a list of player names and score. When I got the list, I immediately call GetRank for the first player name of the list returned by GetLeaderboard. See code below.

         GamingService.Instance.GetLeaderboard(GamingService.LeaderboardId, ls, playerName, NumberOfScoreToFetch, lb => 
            {
                Debug.Assert(lb.Success);

                if (lb.Success && lb.Data.Scores.Count > 0)
                {
                    string firstUserName = lb.Data.Scores[0].UserName;
                    GamingService.Instance.GetRank(GamingService.LeaderboardId, firstUserName, ls, rank =>
                    {
                        Debug.Assert(rank.Success);

                        for (int i = 0; i < lb.Data.Scores.Count; i++)
                        {
                            Debug.Assert(rank.Data != 0); <-- THIS FAIL

                            scoreData.Add(new ScoreData()
                            {
                                Rank = rank.Data + i,
                                PlayerName = lb.Data.Scores[i].UserName,
                                Points = lb.Data.Scores[i].Points,
                            });
                        }

                        callback(scoreData);
                    });
                }
            });

Karl Seguin

unread,
Jun 14, 2012, 9:05:02 AM6/14/12
to moga...@googlegroups.com
That's not going to work. GetRank is returning 0 because it can't find the player..it can't find the player because it's internally looking for the username + the unique id...but the player you are looking for has a difference unique id. Since mogade doesn't share other's unique ids, there's no way to do this. In other words, GetRank can only be used to get the rank of a player using the device requesting it.

I agree this isn't idea. But there's no easy fix on my side.

Why can't you track the rank in your code? If you start at page 0, it's pretty easy to keep a counter for rank as they page back and forth...you can also figure out how to deal with ties. Even a simple implication could just use page * numberOfRecords.

Karl

trudoe

unread,
Jun 15, 2012, 12:46:55 AM6/15/12
to moga...@googlegroups.com
If I was using the API which take a page number in parameter, I could certainly do what you propose. However, I am trying to track the users around the position of the current user. So I am using GetLeaderboard(..., playerName, ...). I suppose I am going to have to get the rank for the current user.

Thanks you Karl for the explanation!
Reply all
Reply to author
Forward
0 new messages