 Hello there! Welcome back to Gamedev Academy. I'm Shane. Let me know that you have arrived in class by leaving me a comment down below and I will place your name upon the screen as I have done with these people here who have successfully attended the last class. If you tell me which of our houses you're in I'll also put you in a color as well. Last time we made it so that our dynamic heads-up display would start to work with the amount of lives that we had left but in this one we're going to set up the score counter as well. That'll tell us how many points we've got and it'll also internally happen in the game mode as well so the game knows how many points we've got. So we're not waffle about it anymore we'll just do it. So let's get stuck in. Now that we've got the HUD working with the lives and that's all being tracked we're now going to do the same for the score. So we've got to get the game mode set up to track the score and also feed that information through to the heads-up display so that that's all working correctly. And we'll start by setting up the binding in the HUD just like we did for the lives. So let's make sure we've got the HUD open. We have. I'll just zoom in a touch. So we're going to be working on this box here which is where our placeholder score is and we're going to go into here and create a binding for that which again opens our widget blueprint as in the previous step. In here we need to create a new variable for the HUD and we're going to call it points. So we've got lives already so let's make a new one and we'll call it points. Of course we don't want it to be a boolean because that won't work that can only be true or false so we'll change it to an integer which will work for our purposes just nicely. And then so we can work with that we're just going to compile the blueprint and that means that we can now drag the points in. So we're just going to start by getting the points like so. And as in the previous step we need to get a two text node so that we can return that into the return node up here. So we're getting whatever the point should be return value is going to be changed to text and then send that to the on-screen display. We now need to go back into our game mode. So there it is, BO game mode. And I'm looking for my reset event because when we reset the game what we've got happening so far is we're just resetting the lives but we're also going to need to reset the score back to zero. So that's what we'll set up now. So what we're going to do is we've already got our HUD here so we're just going to drag out of here and we're going to set the points. So there's points there we can set that and we're going to be setting it to zero. That will work nicely. So now when we reset the game the two elements of the heads-up display are going to be set the lives to whatever the max lives are and then set points back down to zero. Now would be a good time to compile that to make sure that that's all going to be working properly. Now what we're going to need to do is create a new custom event within the game mode and we're going to use that custom event to actually keep score to update the score. So we'll right-click create a new custom event. I'm going to call this update score like so. We're also going to need a variable in this game mode to track the score. So we'll create a new variable and we're going to call that current points like that. That's already coming as an integer for me so I don't need to change it that's good and we're going to select this new custom event and on the inputs here we're going to add a new parameter. I'm going to call that parameter points and we'll use that shortly and that's going to be an integer as well. Okay so what we can now do is we've got this current points so we'll drag this in and we're going to set it and we're going to drop this just at the end of our reset game script. So we're setting the score back to zero and we're also setting the score on the HUD back to zero. So that's all working fine. So now we're going to do this update score script which is going to have a check in it. So because we're going to take points off the player whenever they die we need to add a check so that if the score ever goes below zero we just set it to zero we don't want to have minus scores. So we'll set that up now and hopefully it'll all make sense. So the first thing I want to do is just get current points and we're going to add so we're going to do int plus int I believe. Int plus integer plus integer there we go. I'm going to get the points from here which again we can set later and the current points we're going to add those together and then we need to do the check coming out of the result of this because if we're adding minus 500 to 200 that's going to give us minus 300 which we don't want. So we're going to add the check and the check is is it equal to or less than? Like that and we're going to add a branch to this because this is the condition. So I drop that down there and then we can connect that up. So what we're asking is when we update score is the score first of all going to be zero or less than zero. If that's true we just want to set the current score to zero so set current points to zero. So that makes sense if it's false however then we can actually add the score on because we're probably going up rather than down. So if it's false we're going to set the current points again but this time instead of just setting it to zero like that we're going to set it to the result of this addition here. I'll just pop a we'll pop a reroute node in here just to make that a little bit easier to read. There we go. So that's going to add those and set the current points to that but we also then need to so at the moment we're tracking the points but we're not sending it to the HUD. So we need to get that updating there as well. So what we're going to do is get the HUD and then as the HUD we're going to set points to so it's going to follow this whichever way it goes and the points target is going to be the current point. So we'll get this and that's going to go in there like so. So I've got a feeling that I could do with neatening this up a little bit so let's attempt that. Just going to drop a reroute in here so I can follow that. Yeah so that's looking pretty good that makes sense. So I'm going to add a couple of comments while I'm here so I'll add a comment up here for reset game and we'll add another comment here. Oh hello. I'll add another comment on this one for update score. You can see that my use of spaces is very inconsistent. I apologize to that. Try and cut out your use of spaces if you can because you can create problems if you're not thinking. There we are. Reset game update score so far so good. So at the moment we can track the score but we've got nothing yet telling the the score to be counted when we break any of the blocks and that's going to be the final stage of this particular step. We need to get that working so let's compile and save the work we've done here. Make sure everything's compiled and saved in the hood as well and the final place we need to go in this step is the block since that is where the points are being counted. So in the event graph at the moment we've got destroy actor happening but after we destroy it we also want to know how many points was that block worth and then we can add them onto the score so that's going to come after the destroy actor. So we're going to need to cast to our game mode since that's where the score has been counted. So cast to game mode and it's the BO game mode we want and then objects always going to be get game mode otherwise it won't work and then as the game mode we're going to update the score which is what we want to happen. So the target point is that we're going to add on. This is why we added this points to the custom event earlier so we can remove points and we can add them on mostly for adding on actually. So what I'm going to do is get points and this is going to convert to an integer because I had that as a float for some reason that's not a problem so that is now going to get those points and that's what's going to be added on when we update the score so I'm going to compile and save that. So now it's going to be a really good time to test this so what I'm going to do is just play the game and I want to see the score being counted so when I release the ball as soon as it hits some blocks that should start being counted which it is and it's also sending that to the HUD so everything's working as intended so at the moment if I just let the ball go we're not going to lose anything on the score and we're not going to lose any lives because we've not yet set those behaviours up but that is what's coming in the next step so hopefully I will see you in that next step for that information too. Bye! I believe that quality education should be available to everybody and for that reason all of the classes at Game Dev Academy are completely free and we're supported by our very generous school governors over at Patreon. If you'd like to become a Game Dev Academy Governor and support our work as well as helping us to steer the channel in the right direction then use the link in the description to be taken to the Patreon page.