How To Retrieve Friend Scores

Holger Weissböck on November 18, 2013

Hello everyone! I was just able to release the new Flox SDK! This version comes with a new feature many of you have been waiting for: Friend leaderboards.

Players & Scores

You most likely know that Flox allows you to identify your players as well as their data. You most likely also know that Flox supports any number of leaderboards which allow you to track your player’s game progress and highscores. You can retrieve the scores from these leaderboards in three different time scopes: “Today”, “This Week” & “All Time”.

What you don’t know is that you can now also retrieve the scores of a player’s friends. Uhm, what I meant to say is: now you do know … because I just told you!

Want Some Code?

Retrieving player scores is equally straight-forward as retrieving their time-based counterparts: just submit a list of player IDs to the Flox.loadScore(...) method and the resulting list of scores will consist of these players’ top scores.

var friendIds:Array = ["playerId1", "playerId2", "playerId3"];

Flox.loadScores("default", friendIds,
    function onComplete(scores:Array):void {
        trace("retrieved " + scores.length + " scores");
    },
    function onError(error:String, cachedScores:Array):void {
        trace("error loading scores: " + error);
        //however: we can show the scores from the cache
    }
);

In the example above we pretend that we have a list of IDs of the current players friends, since you’ll most likely use this new feature to build leaderboards that consist of a player’s friends or social connections.

However, since the loadScore(...) method accepts any list of player IDs you can build various custom leaderboards as long as your players huddle together in some form of group-like structure. I’m thinking something along the lines of “Players In This Facebook Group”, “Players Currently Listening To Metallica”, etc… ;-)

Even More Leaderboard Fun

Given this new feature we were also able to improve the web interface for leaderboards. It is now possible to jump from specific scores to their player entities, see the scores a player has reported on your custom leaderboards and jump back to the corresponding leaderboards.

By the way, if you want to make use of this new feature you’ll need to update your Flox SDK.

Have fun!