# Leaderboards

#### Leaderboards Type

Type of leaderboards on the current platform.

```gdscript
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.

{% tabs %}
{% tab title="Godot 3.x" %}

```gdscript
func _ready():
    var leaderboardId = "YOUR_LEADERBOARD_ID" # id that you specified in the config file
    var score = 42
    Bridge.leaderboards.set_score(leaderboardId, score, funcref(self, "_on_set_score_completed"))

func _on_set_score_completed(success):
    print(success)
```

{% endtab %}

{% tab title="Godot 4.x" %}

```gdscript
func _ready():
    var leaderboardId = "YOUR_LEADERBOARD_ID" # id that you specified in the config file
    var score = 42
    Bridge.leaderboards.set_score(leaderboardId, score, Callable(self, "_on_set_score_completed"))

func _on_set_score_completed(success):
    print(success)
```

{% endtab %}
{% endtabs %}

#### Get Entries

{% hint style="info" %}
Works only when `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.

{% tabs %}
{% tab title="Godot 3.x" %}

```gdscript
func _ready():
    var leaderboardId = "YOUR_LEADERBOARD_ID" # id that you specified in the config file
    Bridge.leaderboards.get_entries(leaderboardId, funcref(self, "_on_get_entries_completed"))

func _on_get_entries_completed(success, entries):
    print(success)
    
    for entry in entries:
        print("ID: " + str(entry.id))
        print("Name: " + str(entry.name))
        print("Score: " + str(entry.score))
        print("Rank: " + str(entry.rank))
        print("Photo: " + str(entry.photo))
```

{% endtab %}

{% tab title="Godot 4.x" %}

```gdscript
func _ready():
    var leaderboardId = "YOUR_LEADERBOARD_ID" # id that you specified in the config file
    Bridge.leaderboards.get_entries(leaderboardId, Callable(self, "_on_get_entries_completed"))

func _on_get_entries_completed(success, entries):
    print(success)
    
    for entry in entries:
        print("ID: " + str(entry.id))
        print("Name: " + str(entry.name))
        print("Score: " + str(entry.score))
        print("Rank: " + str(entry.rank))
        print("Photo: " + str(entry.photo))
```

{% endtab %}
{% endtabs %}

#### Show Native Popup

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

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

{% tabs %}
{% tab title="Godot 3.x" %}

```gdscript
func _ready():
    var leaderboardId = "YOUR_LEADERBOARD_ID" # id that you specified in the config file
    Bridge.leaderboards.show_native_popup(leaderboardId, funcref(self, "_on_show_native_popup_completed"))

func _on_show_native_popup_completed(success):
    print(success)
```

{% endtab %}

{% tab title="Godot 4.x" %}

```gdscript
func _ready():
    var leaderboardId = "YOUR_LEADERBOARD_ID" # id that you specified in the config file
    Bridge.leaderboards.show_native_popup(leaderboardId, Callable(self, "_on_show_native_popup_completed"))

func _on_show_native_popup_completed(success):
    print(success)
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wiki.playgama.com/playgama/sdk/engines/godot/leaderboards.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
