PlayerIO

The fastest way to build online games without breaking a sweat.

HTML5 (Javascript) Client Reference

javascript (html5) leaderboards class informationClass leaderboards

Language: Javascript (HTML5)

The Leaderboard service. This class has methods for setting a player's score on a leaderboard, getting the number of players on a leaderboard, and getting toplists of players or the neighbourhood of players around the current player. Leaderboard groups have to be defined in the admin panel first.

Example

Here's how to set a player's score in the default leaderboard of the group "score":

Example

Here's how to get the number of players in a default leaderboard:

Example

Here's how to get the top 10 players in a default leaderboard:

Example

If you know there are more than 10 players in the entire leaderboard, here's how to get the next page of 10 entries:

Example

If you want to get the rank and score of a single player, pass in the connectUserId as a filter:

Example

You can pass in multiple connectuserids to get a filtered list of only those players.For example, by passing in a list of friends of the current player, you can get a toplist for the friends. Don't forget to also pass in the connectuserid of the current player if you want his position as well:

Example

The GetTop method starts at the top of the leaderboard, but if you want to know which players are immediately surrounding the current player, use the GetNeighbourhood method. The index parameter can be either positive or negative. If you use a negative number, the results will start above the current player, with better players, player who have a lower rank than the current player, and a better score. An index of 0 means the current player, and a positive index means that you start below the current player, with worse player, players who have a higher rank, and a worse score. For example, to get the 5 players above the current player, the current player himself, and the 5 players directly below, you can do this:

Example

Finally, GetNeighbourhood also takes a list of players that you can use to filter the results, but unlike GetTop, the current player is always automatically included in the filter list. For example, if you have a long list of friends, but want to know which friend is immediately above the current player in the leaderboard, and which friend is immediately below the current player, you can do something like this:

Methods

 
count (group, leaderboard, score, successCallback, errorCallback):

Sets the score for a user on a leaderboard.

getNeighbourhood (group, leaderboard, index, count, filterUserIds, successCallback, errorCallback):

Gets the neighbourhood of entries of a leaderbord around the current user.

getTop (group, leaderboard, index, count, filterUserIds, successCallback, errorCallback):

Gets the top entries of a leaderbord.

set (group, leaderboard, score, successCallback, errorCallback):

Sets the score for a user on a leaderboard.

leaderboards.count

count (group, leaderboard, score, successCallback, errorCallback):

Sets the score for a user on a leaderboard.

Arguments

group:string
The identifier of the leaderboard group.
leaderboard:string
The identifier of the specific leaderboard in the group, or null for the default leaderboard.
score:number
The score to set for the user.
successCallback:function(Number)
Callback function that will be called when the operation has been completed.
errorCallback:function(PlayerIOError)
Callback function that will be called if an error occurs.

leaderboards.getNeighbourhood

getNeighbourhood (group, leaderboard, index, count, filterUserIds, successCallback, errorCallback):

Gets the neighbourhood of entries of a leaderbord around the current user.

Arguments

group:string
The identifier of the leaderboard group.
leaderboard:string
The identifier of the specific leaderboard in the group, or null for the default leaderboard.
index:Number
What index to start getting entries from. An index of 0 starts at the user. A negative index starts that many entries above the user, and a positive index starts below the user.
count:Number
How many leaderboard entries to get. The max number of entries that can be retrieved per call is 1000.
filterUserIds:string[]
An optional list of users to filter the results by. For example, if you pass in a list of the user's friends, you could get the 10 closest friends above the user.
successCallback:function(leaderboardEntry[])
Callback function that will be called with the loaded entries.
errorCallback:function(PlayerIOError)
Callback function that will be called if an error occurs.

leaderboards.getTop

getTop (group, leaderboard, index, count, filterUserIds, successCallback, errorCallback):

Gets the top entries of a leaderbord.

Arguments

group:string
The identifier of the leaderboard group.
leaderboard:string
The identifier of the specific leaderboard in the group, or null for the default leaderboard.
index:Number
What index to start getting entries from. An index of 0 starts at the user with rank #1, an index of 100 starts at the user with rank #101, etc.
count:Number
How many leaderboard entries to get. The max number of entries that can be retrieved per call is 1000.
filterUserIds:string[]
An optional list of users to filter the results by. For example, if you pass in a list of the user's friends, you could get the 10 best friends, and their absolute rank.
successCallback:function(leaderboardEntry[])
Callback function that will be called with the loaded entries.
errorCallback:function(PlayerIOError)
Callback function that will be called if an error occurs.

leaderboards.set

set (group, leaderboard, score, successCallback, errorCallback):

Sets the score for a user on a leaderboard.

Arguments

group:string
The identifier of the leaderboard group.
leaderboard:string
The identifier of the specific leaderboard in the group, or null for the default leaderboard.
score:number
The score to set for the user.
successCallback:function(leaderboardEntry)
Callback function that will be called when the operation has been completed.
errorCallback:function(PlayerIOError)
Callback function that will be called if an error occurs.