https://sbox.game/c/gamejam2 and free entry led me to interest in joining. I wanted to make the most basic game I could. something with cubes and a leaderboard. At first it was an endless runner where the cubes pushed the player backwards into lava. But push physics needed more tweaking than I was interested in figuring out. The game pivoted to a procedural generation endless jumper / obby.
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
I learned my reliance on a debugger. Figuring out issues in the game worked slowly with console log messages. Despite being able to copy/paste a working example of a leaderboard, setting up the leaderboard was frustrating. Like most of the error messages I encountered, I don't have a clue why it doesn't work. I plan to pause updating this game until I'm able to attach a debugger and hit breakpoints. AKA on pause until this issue is addressed https://github.com/Facepunch/sbox-issues/issues/1784
Comments