Enhance competitiveness by integrating leaderboards, allowing players to compare their scores and achievements.
Support
Use this to determine if you can implement leaderboards for your game on the current platform.
Check if the leaderboard feature is supported on the platform.
bridge.leaderboard.isSupported
Check if built-in popup is supported.
bridge.leaderboard.isNativePopupSupported
Check if multiple boards are supported.
bridge.leaderboard.isMultipleBoardsSupported
Check if user can set score to leaderboard.
bridge.leaderboard.isSetScoreSupported
Check if user can retrieve their score.
bridge.leaderboard.isGetScoreSupported
Check if user can access leaderboard entries including other players' scores.
bridge.leaderboard.isGetEntriesSupported
Player Scores. Set
Submit the player's score to the leaderboard to update their rank and position.
let options = { }
switch (bridge.platform.id) {
case 'yandex':
options = {
leaderboardName: 'YOUR_LEADERBOARD_NAME',
score: 42
}
break
case 'facebook':
options = {
leaderboardName: 'YOUR_LEADERBOARD_NAME',
score: 42
}
break
case 'lagged':
options = {
boardId: 'YOUR_LEADERBOARD_ID',
score: 42
}
break
case 'y8':
options = {
table: 'YOUR_LEADERBOARD_NAME',
points: 42
}
}
bridge.leaderboard.setScore(options)
.then(() => {
// success
})
.catch(error => {
// error
})
Player Scores. Get
Retrieve the player's score from the leaderboard to display their current standing.
let options = { }
switch (bridge.platform.id) {
case 'yandex':
options = {
leaderboardName: 'YOUR_LEADERBOARD_NAME',
}
break
case 'facebook':
options = {
leaderboardName: 'YOUR_LEADERBOARD_NAME',
}
case 'y8':
options = {
table: 'YOUR_LEADER_BOARD_NAME',
}
break
}
bridge.leaderboard.getScore(options)
.then(score => {
console.log('Score: ' + score)
})
.catch(error => {
// error
})
Get Full Leaderboard
Retrieve entries from the leaderboard, including the player's rank and score, to display a comprehensive leaderboard.
let options = { }
switch (bridge.platform.id) {
case 'yandex':
options = {
leaderboardName: 'YOUR_LEADERBOARD_NAME',
includeUser: true, // default = false
quantityAround: 10, // default = 5
quantityTop: 10 // default = 5
}
break
case 'facebook':
options = {
leaderboardName: 'YOUR_LEADERBOARD_NAME',
count: 10, // default = 5
offset: 10 // default = 0
}
break
case 'y8':
options = {
table: 'YOUR_LEADERBOARD_NAME',
perPage: 5, // optional default = 20. Max 100
page: 1, // optional default = 1
mode: 'alltime', // optional 'alltime' | 'last30days' | 'last7days' | 'today' | 'newest'
}
}
bridge.leaderboard.getEntries(options)
.then(entries => {
switch (bridge.platform.id) {
case 'yandex':
entries.forEach(entry => {
console.log('ID: ' + entry.id)
console.log('Name: ' + entry.name)
console.log('Photo: ' + entry.photo)
console.log('Score: ' + entry.score)
console.log('Rank: ' + entry.rank)
})
break
case 'facebook':
entries.forEach(entry => {
console.log('ID: ' + entry.playerId)
console.log('Name: ' + entry.playerName)
console.log('Photo: ' + entry.playerPhoto)
console.log('Score: ' + entry.score)
console.log('Rank: ' + entry.rank)
})
break
case 'y8':
entries.forEach(entry => {
console.log('ID: ' + entry.playerid)
console.log('Name: ' + entry.playername)
console.log('Score: ' + entry.points)
console.log('Rank: ' + entry.rank)
})
break;
}
})
.catch(error => {
// error
})
Shows leaderboard entries built-in popup
let options = { }
switch (bridge.platform.id) {
case 'y8':
options = {
table: 'YOUR_LEADERBOARD_NAME',
}
break
}
bridge.leaderboard.showNativePopup(options)
.then(() => {
// success
})
.catch(error => {
// error
})