0

I am writing a custom leaderboard and I just want to know given the player ID, where he/she is on the leaderboard.

I have found this thread: Rank of Local authenticated player in All Time best in game center leaderboard

But I am having trouble implementing it. Here is what I have:

-(void) retrieveScoresForPlayers:(NSArray*)players
                        category:(NSString*)category
                           range:(NSRange)range
                     playerScope:(GKLeaderboardPlayerScope)playerScope
                       timeScope:(GKLeaderboardTimeScope)timeScope
{
    if (isGameCenterAvailable == NO)
        return;

    GKLeaderboard* leaderboard = nil;
    if ([players count] > 0)
    {
        //leaderboard = [[[GKLeaderboard alloc] initWithPlayerIDs:players] autorelease];
        leaderboard = [[[GKLeaderboard alloc] initWithPlayerIDs:[NSArray arrayWithObject:[GKLocalPlayer localPlayer]]] autorelease];
    }
    else
    {
        leaderboard = [[[GKLeaderboard alloc] init] autorelease];
        leaderboard.playerScope = playerScope;
    }

    if (leaderboard != nil)
    {
        leaderboard.timeScope = timeScope;
        leaderboard.category = category;
        leaderboard.range = range;

        [leaderboard loadScoresWithCompletionHandler:^(NSArray* scores, NSError* error)
         {
             [self setLastError:error];
             //[delegate onScoresReceived:scores];
             if (_gkhDelegate != NULL) {
                 _gkhDelegate->onScoresReceived([self convertNSArrayOfGKScoresToCppVector:scores]);
             }
         }];
    }
}

Whenever I print the rank though, it is always 1 regardless of the actual number. I suspect it's returning the rank in the query. How do I return the abolute position in the leaderboard?

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
Satchmo Brown
  • 1,409
  • 2
  • 20
  • 47
  • I don't see where you're getting the rank, I only see where you're getting the list of scores. – AdamPro13 Feb 04 '15 at 01:54
  • @AdamPro13 What would be the correct way to go about doing this? I figured that it was done automatically when they re passed to the completion handler. – Satchmo Brown Feb 04 '15 at 01:56

1 Answers1

0

It looks like after you receive the scores, it is calling the onScoresReceived delegate method and passing in the vector of scores.

You will want to implement that delegate method so you can take the vector of scores & sort the objects by score if needed (not sure if they'll already be sorted). Each GKScore has a player property that you should be able to compare & see if that player matches your local player.

AdamPro13
  • 7,232
  • 2
  • 30
  • 28