Leaderboards
Enhance competitiveness by integrating leaderboards, allowing players to compare their scores and achievements.
Leaderboards Type
Type of leaderboards on the current platform.
bridge.leaderboards.type
not_available
Leaderboards are not available. Any leaderboard functionality must be disabled in the game.
in_game
Leaderboards are available.
The game must use the setScore
method to set the player's score.
The game should display custom in-game leaderboards using the data from the getEntries
method.
native
Leaderboards are available.
The game must use the setScore
method to set the player's score.
The game should not display custom in-game leaderboards because leaderboards are displayed in the platform interface and the getEntries
method does not work.
Setup
Setup leaderboards in the config file. For each leaderboard add an id
. You can override which id is sent to the platform's native SDK.
{
...
"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.
local bridge = require("bridge.bridge")
function init(self)
local leaderboardId = "YOUR_LEADERBOARD_ID" -- id that you specified in the config file
local score = 42
bridge.leaderboards.set_score(leaderboardId, score, function ()
-- success
end, function ()
-- error
end)
end
Get Entries
Retrieve entries from the leaderboard, including the player's rank and score, to display a custom leaderboard in the game.
local bridge = require("bridge.bridge")
function init(self)
local leaderboardId = "YOUR_LEADERBOARD_ID" -- id that you specified in the config file
bridge.leaderboards.get_entries(options, function (_, data)
-- success
for key, value in pairs(data) do
print("ID:", value.id)
print("Name:", value.name)
print("Photo:", value.photo)
print("Score:", value.score)
print("Rank:", value.rank)
end
end, function ()
-- error
end)
end
Last updated