Leaderboards

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.

bridge.leaderboard.isSupported

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: 'YOU_LEADERBOARD_NAME',
            score: 42
        }
        break
     case 'facebook':
        options = {
            leaderboardName: 'YOU_LEADERBOARD_NAME',
            score: 42
        }
        break
    case 'lagged':
        options = {
            boardId: 'YOU_LEADERBOARD_ID',
            score: 42
        }
        break
}

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: 'YOU_LEADERBOARD_NAME',
        }
        break    
}

bridge.leaderboard.getScore(options)
    .then(score => {
        console.log('Score: ' + score)
    })
    .catch(error => {
        // error
    })
let options = { }

switch (bridge.platform.id) {
    case 'yandex':
        options = {
            leaderboardName: 'YOU_LEADERBOARD_NAME',
        }
        break
    case 'facebook':
        options = {
            leaderboardName: 'YOU_LEADERBOARD_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: 'YOU_LEADERBOARD_NAME',
            includeUser: true, // default = false
            quantityAround: 10, // default = 5
            quantityTop: 10 // default = 5
        }
        break
    case 'facebook':
        options = {
            leaderboardName: 'YOU_LEADERBOARD_NAME',
            count: 10, // default = 5
            offset: 10 // default = 0
        }
        break
}

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
        }
    })
    .catch(error => {
        // error
    })

Last updated