Fetches a number of entries from the specified leaderboard.
The leaderboard must be previously retrieved via gog_create_leaderboard.
Positions start at 1. End position is inclusive, so to fetch first 10 items you could do
gog_download_scores("best_winners", 1, 10);
The operation is asynchronous and dispatches an async event when completed. async_load will contain the following fields:
- event_type: set to "gog_leaderboard_download".
- lb_name: name of the leaderboard in question.
- success: whether the request succeeded.
- result: 1 if successful, anything else on failure.
- numEntries: number of entries received.
- entries: if successful, contains a string with JSON data for entries, such as
{ "entries": [
{ "user": "194040212412504931", "name": "GalaxyTest", "score": 2, "rank": 1 },
{ "user": "191102906021773312", "name": "YellowAfterlife", "score": 1, "rank": 2 }
] }
where per-entry fields are as following:
- user: GOG user ID (including bit flags) as a string.
- name: User's display/persona name.
- rank: User's rank (1 for first place).
- score: User's score.
Returns whether the async operation started (no early error).
For example, if you wanted to fill out a number of leaderboard_ variables when the scores are received, you could add the following code to Async - Steam event:
if (async_load[?"event_type"] == "gog_leaderboard_download") {
if (async_load[?"success"]) {
var entries_map = json_decode(async_load[?"entries"]);
var entries_list = entries_map[?"entries"];
leaderboard_count = async_load[?"numEntries"];
// in old versions of GMS you'd instead do
// if (leaderboard_count > 0) leaderboard_rank[leaderboard_count - 1] = 0;
leaderboard_rank = array_create(leaderboard_count);
leaderboard_score = array_create(leaderboard_count);
leaderboard_name = array_create(leaderboard_count);
for (var i = 0; i < leaderboard_count; i++) {
var entry = entries_list[|i];
leaderboard_rank[i] = entry[?"rank"];
leaderboard_score[i] = entry[?"score"];
leaderboard_name[i] = entry[?"name"];
}
ds_map_destroy(entries_map);
show_debug_message("Got " + string(leaderboard_count) + " entries.");
} else {
show_debug_message("Failed to fetch entries.");
}
}