# Leaderboards

#### Leaderboards Type

Type of leaderboards on the current platform.

```csharp
Bridge.leaderboards.type
```

<table><thead><tr><th width="176.140625">Type</th><th>Game Logic</th></tr></thead><tbody><tr><td><code>NotAvailable</code></td><td>Leaderboards are not available. Any leaderboard functionality must be disabled in the game.</td></tr><tr><td><code>InGame</code></td><td><p>Leaderboards are available. </p><p>The game must use the <code>SetScore</code> method to set the player's score.</p><p>The game should display custom in-game leaderboards using the data from the <code>GetEntries</code> method.</p></td></tr><tr><td><code>Native</code></td><td><p>Leaderboards are available. </p><p>The game must use the <code>SetScore</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>GetEntries</code> method does not work.</p></td></tr><tr><td><code>NativePopup</code></td><td><p>Leaderboards are available. </p><p>The game must use the <code>SetScore</code> method to set the player's score.</p><p>The game should call <code>ShowNativePopup</code> to display leaderboards overlay and the <code>GetEntries</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.

```csharp
private void Start()
{
    var leaderboardId = "YOUR_LEADERBOARD_ID"; // id that you specified in the config file
    var score = 42;
    Bridge.leaderboards.SetScore(leaderboardId, score, OnSetScoreCompleted);
}

private void OnSetScoreCompleted(bool success)
{
    if (success)
    {
        // Operation succeeded
    }
    else
    {
        // An error occurred
    }
}
```

#### Get Entries

{% hint style="info" %}
Works only when `Bridge.leaderboards.type` = `InGame`
{% endhint %}

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

```csharp
private void Start()
{
    var leaderboardId = "YOUR_LEADERBOARD_ID"; // id that you specified in the config file
    Bridge.leaderboards.GetEntries(leaderboardId, OnGetEntriesCompleted);
}

private void OnGetEntriesCompleted(bool success, List<Dictionary<string, string>> entries)
{
    Debug.Log($"OnGetEntriesCompleted, success: {success}, entries:");
    
    if (success)
    {
        foreach (var entry in entries)
        {
            Debug.Log("ID: " + entry["id"]);
            Debug.Log("Score: " + entry["score"]);
            Debug.Log("Rank: " + entry["rank"]);
            Debug.Log("Name: " + entry["name"]);
            Debug.Log("Photo: " + entry["photo"]);
        }
    }
}
```

#### Show Native Popup

{% hint style="info" %}
Works only when `Bridge.leaderboards.type` = `NativePopup`
{% endhint %}

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

```csharp
private void Start()
{
    var leaderboardId = "YOUR_LEADERBOARD_ID"; // id that you specified in the config file
    Bridge.leaderboards.ShowNativePopup(leaderboardId, OnShowNativePopupCompleted);
}

private void OnShowNativePopupCompleted(bool success)
{
    if (success)
    {
        // Operation succeeded
    }
    else
    {
        // An error occurred
    }
}
```
