Building a Leaderboard in Godot (Making Cyberglads 8)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi and welcome to this eighth installment in the making cyber glass series I'm building a game called cyber glads using the Godot game engine in the last episode we introduced a scoring system for cyber glads every time the player goes through the entire current version of the game playing all three NPCs one after the other a total score is calculated that adds some replayability to the game players will want to replay multiple times to improve on their score as an added incentive it would be nice to create a leaderboard with the high scores from all players in order to do that we'll need to persist these scores in a back-end server of some sorts so that we can remember all the scores and we can show the same leaderboard to all the players wherever they are in the world further back in part I'm going to use silent Wolf's silent waffles a service that I built myself for the purposes of cyber glads it's available as a Godot plugin so you can use it if you want to add a leaderboard to your own game for free otherwise there are alternative back-end solutions and of course you can build your own game server one advantage with silent wolf is that it plays nice with Godot it's also really easy to use I'm going to download it now from the silent wolf website so here I am on silent wolf comm I'm just going to really quickly create an account right and so I should have received an email with a confirmation code and I have here it is that's right okay okay so I have an account next step I'm going to ask silent wolf to generate an API key and the game ID for me so my games name is cyber glass and here's my API key and my game ID is just cyber clad so I'm just going to remember them for later right next step I'm going to download the sample of plugin for Godot by just clicking on this link and there so you can follow I'm just going to switch to the file system view so here I have a zip file that I've just downloaded from the sound wolf website and I'm just going to copy it over to the add-ons folder of my Godot project and I'm going to unzip this file here extracting all the contents and I'm going to get rid of the zip file and now if I go back to my Godot editor I should see the contents of the plugin in here I do right as a side note you may have noticed that I'm now using to do a 3.1 for the first time in this series parting the game to 3.1 didn't imply any changes to the game so far so it's been really smooth but so don't be surprised if the Godot editor interface looks a little different from previous episodes it's just that I've upgraded to the latest stable version of Godot back to our plugin you'll want to make sure that the plugin is ought to loaded into your game just like our global script to do so I'm just going to go to parodic settings and here my autoload tab I'm just going to put in the path to my silent wolf GD script and I'm going to put silent wolf as the name and are you going to add it and here it's enabled as an auto loaded script right last step before we can you we need to configure the plugin if you open the GD script file called salt wolf thuggees so the one we've just mentioned as the one that we wanted auto loaded we see the expected configuration here you could just fill in the values in these two JSON objects that you see there but I don't recommend it because if you want to install a newer version of the plugin in the future it will overwrite your convict along with the rest of the plugin the best way to configure the silent wolf plug-in is by using the built-in configure functions ideally you would call them from an auto loaded singleton so for us that would be the global script so I'm going to go to my global script and inside my ready function I'm just going to add these two calls to the silent wolf configure API and I'm just going to make sure to use the correct API key and game ID here we go just going to properly indent this code there so the first function call here is just to set some general configuration for your game your API key your game ID and your game version there's also configuration specific to the scores feature that we're going to use to make our leaderboard this just tells the plug-in what scene to open when the leaderboard is closed now that that's done I'm ready to add a leaderboard to my game so back to cyber glads you remember that I set up a loop where the player can play against the three named NPCs in succession when the loop finishes so either when the player character dies at some point or if the player defeats Kermit the final opponent in the game loop we need to call the server to save the new score so remember my arena scene so this is my arena scene and I've added a little dialogue that is invisible by default it will appear at the end of the three NPC game loop where the user will be prompted for his name and to submit a score just going to make it invisible again and so that button here submit score we want to it has a pressed event of course like all buttons and Godot and we're going to connect a signal to this pressed event that will trigger a function on my arena script and so here in my arena script you see that a new function has been you know about signals by now and I'm just going to replace the default code in there by this right so this function takes the players chosen name from the dialogue input field and sets it in a variable and the global object and then calls the silent wolf persist score function passing the players name and the game's total score finally I'm getting the latest high scores from the server using the get high scores function and I'm hiding the dialog box so that we don't need it anymore because we don't need it anymore behind the scenes silent wolf uses godot's HTTP requests node to perform these calls over HTTP but you don't need to know anything about that because silent wolf takes care of that complexity for you now that we know how to store new scores and retrieve them we want to show them in the form of a leaderboard we could build a new leaderboard from scratch using container panel and label nose you can find out how to play with these node types to build a UI and Godot in my previous videos on building a splash page and a head of display but here I'm just going to use the built in leaderboard scene that comes with the silent wolf the sound wolf plugin so I'm just going to add a little function whose responsibility will just be to whoops here we go you function here who will just load the default leaderboard scene from directly from the solid wolf plugin in my arena scene I've added another button so this one so I'm just going to show that 2d view so you can see it there's also invisible by default here we go that will show the leaderboard at the end of a fight or at the end of the three character fight loop pressing this button will load some wolves out of the box the leaderboard scene and I just need to make sure that the pressed event on this button actually triggers the function that we've just fine and so here I'm going to connect another signal here to a new function and this new function will just call the one that I've just defined here right you can of course customize the layout of the leaderboard scene if you do I recommend to create a new scene that extends from the plugins leaderboard scene and attach a script that extends from the leaderboard script otherwise your changes will once again be overwritten by future versions of the plug-in you can also look at the scene and it's attached script to draw inspiration from it and make your own leaderboard let's test the leaderboard end-to-end I'm going to go through the three NPCs to get a new score and then take a look at the leaderboard so I'm just going to run the game now here we go and switch to the game run window here we go so I'm going to play all three names NPCs in succession so you remember that an increasing order of difficulty it's Ernie than birds than Kermit here we go Ernie is not much of a challenge here goes Bert he's a lot faster I got him but I don't have a lot of HP left for Kermit so let's try Oh didn't survive for long there okay so you see here my final score is 18 not the best score and here I'm prompted as expected for my name and I can submit my score to the backend and now I can show my veto board right so here's the latest leaderboard and you can see that my latest score has already been added the leaderboard scene checks whether the top scores have been loaded from the backend and if not it fetches them in either case it displays the latest results by default it retrieves an ordered list of the top 10 scores but you can request more or less through the plugins configuration or using the API that's how easy it is to integrate a leaderboard into your own game you can dig into the code to see how the leaderboard scene works under the hood so if I go back to my editor window and open my leaderboard GD script here when the leaderboard is loaded it checks whether we've already retrieved the scores from the backend if so we still have to make sure that we have all the players the latest game scores to display the plugin saves all of the players own scores locally and the leaderboard will merge the scores from the backend with a local scores to show the player how his latest efforts match up with best without having to do another round trip to the server if no backin scores have been loaded yet the leaderboard will try to retrieve them while we're waiting for the back-end call to complete we want to show a loading message and then replace it with a list of scores once we have them to do this I'm using a Godot feature called a co-routine co-routines that you stop the execution of a function until something happens and then resume it at the point where you stopped it earlier this year that you see that you see here does the trick in this case we're waiting for a signal called scores received to be emitted before rendering the leaderboard the signal in question is emitted by the plugins score script once we get an answer back from the backend tor get high scores a request code routines are really useful in combination with signals we're going to use them a lot more in the future of course since we started from scratch with a new game on the first to play it and so there's only one score in the leaderboard let's add a little script that will run the next time the arena loads to add some more scores so that we can have a proper leaderboard rendered so I'm just going to add some temporary code here to my splash GD so in my load arena function I'm just going to add this little script that is just a series of sound Wolf's API calls to persist some arbitrary scores here will remove this after the next game right now let's just play the game again I don't actually have to face all three NPC's to see the leaderboard again it's also displayed after regular fights so here I'm going to just stop the previous game I'm going to run the game again I'm going to move to the game run window there we go and I'm just going to play against birds just playing against Birds it's the fastest route to their show leaderboard button and here I have it I don't really care about less corn this match I'm going to show the leaderboard again and here I have all my scores loaded and my own real score is in there and the bottom tier there and all these arbitrary scores have been loaded as well right so this was a pretty run-of-the-mill implementation of a leaderboard but there are lots of other things that you can do with leaderboards and lists of player scores and stats ours is a global leader board meaning it remembers all the scores of all the players who have ever played this version of the game but sometimes this isn't the most compelling thing you can show especially to new players because if they're not one of the top players of the game their names will never appear on the global even leaderboard instead if the player isn't in the top ten you may want to show a part of the leaderboard that isn't in the top of the rankings that isn't top to the top of the rankings but maybe the five players who rank just above and below the players latest score that way the players the players have an idea of where they stand it gives them a short-term target in terms of who they could overtake if they improve their performance just a little grouping users by skill level also has benefits in multiplayer games where you could use this information to do matchmaking to go one step further you could then organize tournaments and leagues where getting to the top of a certain leaderboard unlocks the next stage of the competition you may want to group players differently so you have an RPG type game with different classes of characters like wizards and knights and barbarians you might want to have different leaderboards for each class or if your game has a geographical dimension like in the case of an augmented reality game that you play outdoors you can implement the neighborhood leaderboard or a city leaderboard if the purpose of your game is to have players play with their friends you could help you could also have a social centric leaderboard or you could see how well you did compared to the people that you know time-based leaderboards are another option just rank players alongside whoever else is playing on that day or at that moment Mungo's game room has a video about how fortnight uses different leaderboards to keep players interested whatever their level in addition to global wins you get a revolving leaderboard that is reset every week and tells you how often you've been in the top 10 or the top 20 you also have alternate leaderboards where you are grouped together with a random batch of 50 other players what should you display on the leaderboard here we just put the players in-game name along with their score in the ranking but you might want to add more visuals to your leaderboard by including each player's avatar we could also have added the scores that each player got for fighting each of the three NPCs and then maybe a rank the players performance per NPC so there are plenty of ways of getting creative with leaderboards if you're looking for a great read on the subject I recommend a medium article called how to motivate using leaderboards or the author's home organ I and Steven ledbetter explore the psychology of leaderboards beyond the scope of video games and how to design the perfect leaderboard for your application if you have an interesting use case for a leaderboard I'd love to hear about it so don't hesitate to reach out that's it for this edition of cyber glads as always you can download the latest version of the game on the cyber glass comm website let's see whether you can make the leaderboard thanks for listening
Info
Channel: Brass Harpooner
Views: 5,189
Rating: undefined out of 5
Keywords: Godot 3.1, Godot plugin, Godot tutorial, Plugin development, Fortnite, Coroutine, HTTPRequest, SilentWolf, Scores, Leaderboard, Backend, Server
Id: g4p1x6-Iyx4
Channel Id: undefined
Length: 14min 58sec (898 seconds)
Published: Mon Jun 10 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.