views:

187

answers:

1

Hi

In their support OpenFeint give you this, but I don't quite understand. How can I get the leaderboard data, say top 10 and show it in my own UI?

Original link: http://www.openfeint.com/ofdeveloper/index.php/kb/article/000028

[OFHighScoreService getPage:1 forLeaderboard:@"leaderboard_id_string" friendsOnly:NO silently:YES onSuccess:OFDelegate(self, @selector(_scoresDownloaded:)) onFailure:OFDelegate(self, @selector(_failedDownloadingScores))];

- (void)_scoresDownloaded:(OFPaginatedSeries*)page
{
    NSMutableArray* highscores = nil;

    if ([page count] > 0)
    {
        if ([[page objectAtIndex:0] isKindOfClass:[OFTableSectionDescription class]])
        {
            // NOTE: In the following line, we access "[page objectAtIndex:1]" to retrieve high scores from
            // the global leaderboard.  Using "[page objectAtIndex:0]" would retrieve scores just for the local player.
            // Older versions of OpenFeint did not break this out into 2 sections.
            highscores = [(OFTableSectionDescription*)[page objectAtIndex:1] page].objects;
        }
        else
        {
            highscores = page.objects;
        }
    }

    for (OFHighScore* score in highscores)
    {
        // ...
    }
}
- (BOOL)canReceiveCallbacksNow
{
    return YES;
} 
+2  A: 

The code to request a page of high scores is the first line, i.e.:

[OFHighScoreService getPage:1 forLeaderboard:@"leaderboard_id_string" friendsOnly:NO silently:YES onSuccess:OFDelegate(self, @selector(_scoresDownloaded:)) onFailure:OFDelegate(self, @selector(_failedDownloadingScores))];

You put this line in the place where you want to start the query for high scores. You can change the page number as required. Once the page of high scores has been retrieved, the callback _scoresDownloaded is called. The example shows you how you would iterate through the OFHighScore objects in the highscores array. You would replace the comment // ... with your own code to show the scores to the player, or whatever.

(In case of error _failedDownloadingScores is called; you should implement that to show an error.)

Arkku
Ahh thats makes a lot of sense now, so I would simply need to put the nsmutablearray highscores into a table? What confuses me is how can I do this when it has multiple sections if you like, it holds the player name, their score and rank. I have never worked with an array that has multiple sections like this, how would I display it?
Josh Kahane
Worked it out thanks!
Josh Kahane