# Leaderboards

#### Leaderboards Type

Type of leaderboards on the current platform.

```javascript
playgama_bridge_leaderboards_type()
```

<table><thead><tr><th width="176.140625">Type</th><th>Game Logic</th></tr></thead><tbody><tr><td><code>not_available</code></td><td>Leaderboards are not available. Any leaderboard functionality must be disabled in the game.</td></tr><tr><td><code>in_game</code></td><td><p>Leaderboards are available. </p><p>The game must use the <code>set_score</code> method to set the player's score.</p><p>The game should display custom in-game leaderboards using the data from the <code>get_entries</code> method.</p></td></tr><tr><td><code>native</code></td><td><p>Leaderboards are available. </p><p>The game must use the <code>set_score</code> method to set the player's score.</p><p>The game should not display custom in-game leaderboards because leaderboards are displayed in the platform interface and the <code>get_entries</code> method does not work.</p></td></tr><tr><td><code>native_popup</code></td><td><p>Leaderboards are available. </p><p>The game must use the <code>set_score</code> method to set the player's score.</p><p>The game should call <code>show_native_popup</code> to display leaderboards overlay and the <code>get_entries</code> method does not work.</p></td></tr></tbody></table>

#### Setup

Setup leaderboards in the [config file](https://wiki.playgama.com/playgama/sdk/playgama-bridge-config). For each leaderboard add an `id`. You can override which id is sent to the platform's native SDK.

```json
{
    ...    
    "leaderboards": [
        {
            "id": "test_leaderboard", // use this id in game logic
            "<ANY_PLATFORM_ID_HERE>": "<OVERRIDED_ID_FOR_PLATFORM_HERE>"
        }
    ]
}
```

#### Set Score

Submit the player's score to the leaderboard to update their rank and position.

```javascript
var leaderboardId = "YOUR_LEADERBOARD_ID" // id that you specified in the config file
var score = 42

playgama_bridge_leaderboards_set_score(leaderboardId, score)

// callback via Async Social Event
if async_load[? "type"] == "playgama_bridge_leaderboards_set_score_callback" {
    if async_load[? "success"] {
        // your logic
    }
}
```

#### Get Entries

{% hint style="info" %}
Works only when `playgama_bridge_leaderboards_type` = `in_game`
{% endhint %}

Retrieve entries from the leaderboard, including the player's rank and score, to display a custom leaderboard in the game.

```javascript
var leaderboardId = "YOUR_LEADERBOARD_ID" // id that you specified in the config file

playgama_bridge_leaderboards_get_entries(leaderboardId)

// callback via Async Social Event
if async_load[? "type"] == "playgama_bridge_leaderboards_get_entries_callback" {
    if async_load[? "success"] {
        var entries = json_parse(async_load[? "data"])
    }
}
```

#### Show Native Popup

{% hint style="info" %}
Works only when `playgama_bridge_leaderboards_type` = `native_popup`
{% endhint %}

Displays the leaderboard overlay, including the player's rank and score.&#x20;

```javascript
var leaderboardId = "YOUR_LEADERBOARD_ID" // id that you specified in the config file

playgama_bridge_leaderboards_show_native_popup(leaderboardId)

// callback via Async Social Event
if async_load[? "type"] == "playgama_bridge_leaderboards_show_native_popup_callback" {
    if async_load[? "success"] {
        // your logic
    }
}
```
