Alpha released
Posted 27 days ago

Finding docs

It was fairly easy to find videos and tutorials on setting up the player controller. The leaderboard was another story. No videos. No mention of it on the official discord. Initially the only online documentation I could find was a couple lines on https://sbox.game/api. The most helpful was by far searching GitHub and coming across this https://github.com/Facepunch/sbox-ss1-scene/commit/117e11b919d38c1df1a98d3863e100000adafaad . Yet, I couldn't get a copy from that commit to display a leaderboard. Which led to several attempts to attach a debugger. All I could tell was there was some issue server side. In that end that's not only where it was, but also had the missing documentation.

Server settings for a leaderboard

After your code for leaderboards is something similar to the commit above. You need to modify the settings for your games' webpage. The first of those setting is on https://sbox.game/[org-name]/[game-name]/edit/features . You'll see 3 checkboxes here. You should check the checkbox for `Stats` and `Leaderbaord`. Doing so enables a new stats tabs on your games webpage.

Clicking the new Stats tab will take you to https://sbox.game/[org-name]/[game-name]/stats/ with 3 little icons. The 1st is some basic documentation on how to use stats in your games code. The 2nd will let you view stats you've already created in code. The 3rd you don't need since stats can be created from code alone.

The screenshot below shows 2nd icon, view stats. The `score` generated from my game containing the line of code `Sandbox.Services.Stats.SetValue("score", MaxScore);`
The three icons to the left of "Leaderboards" give various descriptions of how stats are required for Leaderboards. For me these 3 little icons led to the missing information I was seeking to understand why my leaderboard weren't working! You'll discover leaderboards can't be created from code. They have to be created from the 4th icon, the add button or https://sbox.game/[org-name]/[game-name]/stats/leaderboards/add . Then your code needs to match that name of the leaderboard you created on this webpage. In [example commit the name of the leaderboard is "victory_time" from line 41 of LeaderboardPanel.razor](https://github.com/Facepunch/sbox-ss1-scene/commit/117e11b919d38c1df1a98d3863e100000adafaad#diff-e12852c465164d11e3814dc7a04c48ffa6c6321b808c62abe2d46d41ab1d6463R41).


After the leaderboard is created on the webpage, use the games webpage to setup that leaderboard by clicking its edit tab (https://sbox.game/[org-name]/[game-name]/stats/leaderboards/v/[leaderboard-name]/edit). The most important part is the "Stat Ident" field. The [stat Ident is what score value the leaderboard will use](https://github.com/Facepunch/sbox-ss1-scene/commit/117e11b919d38c1df1a98d3863e100000adafaad#diff-e6376aba491613f49ad3be945c0dce0680d3e6102bf481ad0912ca0f726ced23R637).


Maybe sometime in the future you'll be able to test it with a link like https://sap.facepunch.com/package/leaderboard/1/feddas.infinaobby/height_max/u/76561198060805236/global or
https://services.facepunch.com/sbox/package/stats/infinaobby/u/76561198060805236