Adding Google Play Leaderboards in Godot!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hey what's up guys last time in the android series i showed you the game i built in about four hours and uh went through the plan of what i plan on going over in these various tutorials on my channel so today we start off with the very first of those tutorials which is leaderboards so by the end of this lesson we're going to have something that looks like this so we have a rank at the top which will show you your rank on the leaderboard your high score which will be your all-time high score and then your current score while you're playing and the show leaderboard button will show the leaderboard screen so you can look at everybody else's high score as well so um like once again this is the game here you have a guy you can jump around bounce the balls and you try to bounce them as long as possible so let's just get right into it so to start off i'm going to go over the tools i'm going to be using and then i'm going to go over the project structure of how this was built a little bit just so you know what i'm doing and then we're going to just add leaderboards and it's not an extremely involved process so hopefully this will only take 15 maybe 20 minutes so to begin last time i had mentioned that i had used the version of the plugin on one seed fruit here and you could use this version it still works but what i've done is i've actually forked it and i've actually added a little bit of functionality to it to support what we're going to do today so what i've specifically added is the ability to uh grab the high score and the rank of the player without having to show the leaderboard which didn't exist before so if you're interested in that i'm going to be maintaining my own fork of this as i work through this and at least i know that it's tested and it works and it'll be fairly updated so you can go over to my our github so mobile technologies ptsdp and there's tags and releases and you'll see all my tags will be i have a nose tag on it um just so you know which one it is this is what i'm this is the one i'm going to be using additionally um what i'm going to be using is um instead of using my device to show you to make it a little bit easier on my end we're going to use a android emulator so i'm not going to go too much into how to set up the virtual device further than that if you're having troubles or if it's not working um google it there are a lot a lot of people do android development but once you have it running here uh you'll notice that the little android button shows up which means everything is working so now let's get into the project structure so as i mentioned before it's a very simple application there's only three scripts uh only two of which we're gonna have to touch the player script is just for movement we can ignore that and never use it so we can close that the google play script is basically what i showed you in this video the adding google play services to your application in 30 minutes if you haven't watched that you're going to need to have that before this and then there is the main game script which is very simple we have already when people sign in it emits a signal and we catch that signal in our main function in the signed in here yeah so uh just get player stats this is where we're going to do our leaderboards here and then uh player stats returned here we'll remove that as well i've already implemented everything before but i tried to delete everything and i missed stuff so uh we've got a few simple functions if the ball hits something it figures out if it's a player on the ground if it hits the player it adds the score sets the high score label if it hits the ground then it loses the game and if it sits and then if anything changes we set the labels format labels and we take input and we process physics so it's fairly simple with that out of the way let's add leaderboards so the first thing we're gonna have to do is we're gonna have to go to our uh google play console google play console now we're going to restart a few things from scratch so solo slime is where we want to be in our google play console we'll go to the bottom and play game services and click leaderboard all right so you're going to get a page like this what you're going to do is you're going to just hit create leaderboard you're going to give it a name we're going to call it high scores or actually we're going to call them big chads uh so number of decimals is just to make sure that we don't have uh periods so if you've got fractions you'll want the decimals we're not going to use that uh icon it'll just use a default icon if you don't give one short order that's important if you're playing golf you'll want smallest first us we want largest first tapper protection is to prevent people from screwing up your leaderboards as much as possible so i don't know how effective this is but i was would assume you want it on set lowest allowed score um i'm gonna put zero and highest i'm just going to leave it forever list order uh what is this list order the order in which leaderboards are displayed to users so um one of one i would just leave that default once you have all that done save as draft so you could at this point just choose to publish but once you publish you're not going to be able to reset the data on the leaderboard this reset progress this button isn't available if you publish um i don't know wherever the publish button is it was probably in here review and publish yeah so we don't want to do that what you do want to do is grab your uh leaderboard id here that's all you need to do in the play services for now you'll go back into godot and you'll go into your play services thing i've already added it leaderboard id here and i just need to replace it with the new one so that's my new leaderboard id now with that out of the way first thing we're going to do is make it so that we can show the leaderboard because in order to verify that our leaderboards are working we need to be able to show the various scores so what we're going to do is we're going to go back to our 2d view so i added this button before i didn't wanna it's easy enough to add buttons i don't think i need to show you that um so button two show leaderboards we're going to unpressed and we're gonna facial leaderboard there we go leave that for now and then we're going to go to the other menu because we want to be able to show it on both so button two no button one and on button one we had pressed and again this will be show leaderboard connect all right so short leaderboard will be simple enough what we're going to do is we're going to call play services and we're going to add a function to our play services called show leaderboard so just here play services show leaderboard and then with that done that's all we're going to do here we're going to go to our google play services and we're going to add that function so we'll do it at the top all of our public functions i'll do at the top public functions now sign in here is public as well and i would i want to rename it but we'll just say for now so funk uh show leaderboard now how do we do this so the easiest way to know how to do this is in the readme itself we have show leaderboard and this this is the button here show leaderboard if you have multiple leaderboards there's also the show all leaderboards but we're only doing one so we only need the one and we want to display that specific leaderboard and here we would put leaderboard id and that i believe should be uh play game services just oops i want to make sure to call what we called it there we go and now everything is defined and that should be everything we need to show our leaderboards so let's open it up in the emulator by hitting the android button everything's going to build there you go so it's opening up and we're logged in there we go and now uh since we're logged in we can hit the show leaderboard button and you'll see that we've got the big chats leaderboard that we just made that shows up right so now what we're going to do is uh we're going to submit our scores whenever we get a score um so we're going to do is inside our script function here we are going to go into our main play script and where we have ball hit ground here we are going to call play services submit score score that's all we need to do and then inside here once again we are going to put implement our func submit score function and again we will go to um here and find our submit score so submit score submit leaderboard score is here so we will do this and make sure that we use the one we have change leaderboard id to leaderboard id and here we take score as an integer and with that that should submit our scores so let's uh let's run that on the device now this is how i generally do my programming uh whenever there's not too much overhead i implement one feature at a time then i test it and if it doesn't work i go back test it again test it again test it again until it works and then i do the next feature that way you always know when something breaks when something is fixed and what should be working et cetera et cetera so we've got the game open uh here we hit start we play here oh we got one score and that should have submitted the leaderboard so what show leaderboard you now see that we have a one score top score of one bonk and now let's restart the game two oh and now we've got four that should have submitted as well hit hit show top score four and there we go we were officially saving our top scores automatically and submitting the score every time is not too harmful because it doesn't really matter if it's not higher than what you already have it just won't save it simple as that now what we want to do is get the player's high score on logging in right and also we want to get the rank after we submit the score and on logging in so let's do the logging in part first so when we sign in we call sign in and after we get we sign in we emit the signal signed in on signed in here where is it we were connected to that signal uh on play services here so in signed in we call get player stats and get player stats this is where we're going to call to get our leaderboard data now this is the functionality that i added myself and is only available in once again in this repository mobile technologies pgs gp now um i'm actually going to add the i'm going to add some the the stuff in here um as we go through this because i didn't document it and i should have documented it so let's go in and do that together [Music] all right so we will open up here we're back in the play services all right so now that i've updated the plug-in to um one updated three me and two made some changes i meant to do yesterday when i added the functionalities what i need to do is inside connect signals what we're going to do is we're going to add a couple more connect signals in here now that's uh okay and then we will do this okay and then we will go back into our readme and grab the other functions and these will be on the main page we want these so in here and what we're going to do is on retrieve failed we're actually just going to ignore it um oops score dictionary let's replace that as well all right so we don't actually need to do that but what we will do is create a signal score retrieved and we're going to admit that emit that signal mix tabs into indentation we're going to emit signal here emit signal score retrieved and we are just going to score dictionary there we go so now we get that and what we're going to do is now when we sign in we are going to function the tree score and that's where we're going to call this function and again it's going to be we're worried do you have one one use case but this is how you would do it so leaderboard id and then this will be all time and this will be all and this will be here so now once we finish signing in we sign in we get player stats and that is when we call retrieve score in play services dot retrieve score and there we go now we want to retrieve that every time when we sign in and also when high score submitted so we're going to do that so first thing first we got the score retrieve let's connect that signal and score retrieve so play services dot connect score retrieved so score retrieved and this is going to be very simple we are going to make a function i guess it's here so on sign in we're gonna say funk score retrieve score dict dictionary uh screw it we're just gonna put score dict and in here what we're going to do is we're going to say high score equal verdict score and score uh not score and rank equal verdict rank that should in theory um sign in it'll get the player stats i will get the score it'll call score retrieved uh on leader score retrieved send the dictionary to here and then um update here we say set high score label set rank label right set rank label set high score label and in theory that should work so now let's push that to device and now when we first sign in we should get our rank change from 999 to one because we've got the only score there and there we go rank one score four right on login and that's exactly what we want now one last thing we're going to do and then we're pretty much done with this this tutorial is when we submit our high school high score we're going to then uh after the submission we're going to retrieve our new rank um and high score so what i'm gonna do to prove that it's working and actually i i think it works better this way is we're not automatically gonna set the high score here whenever we reach a new high score so i'm just going to comment that out so when we go up a high score we're just going to um we're going to keep track of the score and we're only gonna update the high score label when we get the new high score from google play services that way um we're always what we show the player is always in sync with what's on google play and it works offline as well because google play does caching and then pushes it up to the server eventually so what we're going to do from that point is let's see when we submit the score let's go back to the web page here when we submit the score we want to we're gonna board leaderboard leaderboard leaderboard there we go we want to on leaderboard score submitted this will be fairly simple so we take this and we'll go into the engine we will go into scripts in our google play we will connect one more thing here we are going to replace play game services with play services and we are going to funk our own leaderboard score submitted and i believe that's a string yeah and leaderboard id meter board id string and all this is going to do is we are going to retrieve score here and that's all we want to do so now when we when we submit our score we are going to get it we're going to get a response when it is submitted and then we're going to just retrieve our high score to make sure that we are updating our client properly so let's do that now let's hit the android button all right so we are now in in the app and this should be our final test so let's just go through all the features to make sure it works show leaderboard works perfectly high score is four bucks and that is properly shown on the screen when we start so let's try to beat four it shouldn't be too hard um it can be hard though let's damn it this is not the easiest all right we beat it let's not get too high six then you see there that it i lost the game it submitted the score and then my high score updated so that's how you add leaderboards to an android application using google play services in godot if you like this video and you're hyped to get to achievements which will be the next one smash that like button subscribe all that crap and i'll see you next time
Info
Channel: Ozzadar
Views: 1,136
Rating: undefined out of 5
Keywords: google play leaderboards, google play leaderboards godot, leaderboards godot, godot game engine, google play godot, android godot, leaderboards, google play, android development, game development, indie dev, godot engine, Google Play, build android game, howto android godot, howto google godot, godot game engine tutorial, godot android plugin, android development 2021, google play store
Id: LtWCoujeR7E
Channel Id: undefined
Length: 21min 20sec (1280 seconds)
Published: Fri Jun 18 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.