Leaderboard Load Scores (Top / Player Centered)
Goal
Load leaderboard scores and iterate cached entries to build a custom leaderboard UI.
Prerequisite
Make sure the player is authenticated first. Use use-case-1-auth-bootstrap.md.
Actions used
GameServicesCreateLeaderboard(cache a leaderboard handle)GameServicesConfigureLeaderboard(scope/time/query size)GameServicesLeaderboardLoadTopScoresorGameServicesLeaderboardLoadPlayerCenteredScoresGameServicesGetLeaderboardLoadScoresSuccessResult(on success; givesscoreCount)GameServicesGetLeaderboardLoadScoresError(on failure)GameServicesGetLeaderboardScoreInfo(iterate entries)(Optional paging)
GameServicesLeaderboardLoadNextPage,GameServicesLeaderboardLoadPreviousPage
Variables
leaderboardId(String) e.g."top_scores"scoreCount(Int),scoreIndex(Int)Per entry:
playerDisplayName(String),rank(Int),scoreValue(Long),formattedScore(String)
Flow
State:
CreateLeaderboardAction:
GameServicesCreateLeaderboard(input:leaderboardId)
State:
ConfigureLeaderboard(optional)Action:
GameServicesConfigureLeaderboardInputs:
playerScope,timeScope,querySize
State:
LoadScoresAction:
GameServicesLeaderboardLoadTopScores(or...LoadPlayerCenteredScores)Events:
successEventβGetScoresMetadatafailureEventβGetLeaderboardLoadScoresError
State:
GetScoresMetadataAction:
GameServicesGetLeaderboardLoadScoresSuccessResultβscoreCountSet
scoreIndex = 0
Loop:
While
scoreIndex < scoreCount:Action:
GameServicesGetLeaderboardScoreInfo(input:scoreIndex)Add entry to UI
scoreIndex++
Notes
Use paging actions when
scoreCountis at yourquerySizeand you want more results.To show native UI instead of building your own, use
GameServicesShowLeaderboardsUI/GameServicesShowLeaderboardUI.
Last updated
Was this helpful?