 Ah hello again, welcome back to Game Dev Academy. I'm Shane, let me know you're here by leaving a comment down below and I will pop your name on screen to show that you are here, just like I've done with these fabulous individuals that you can see now. In the last video we made it so that the score would be counted and that would appear on the heads-up display. Now what we want to do is get it so that when we lose a ball we'll lose a life and that will be shown on the heads-up display as well but also will have an impact on the gameplay so maybe we'll take some points off the player for losing a life. So let's have a look at how we're going to go about that. Now that we've got the score being counted it's going up and we have got the right number of lives being tracked and that's all displayed in the hood which is beautiful. We now need to start taking things away so when the ball goes beyond the paddle we need to take a life and maybe some points as well. So let's get into that. So the first thing I'm going to do is what happens when we lose a life. So I'm going to go into the game mode and I'll create a new custom event and we're going to call that life lost. So this is what's going to happen when we lose a life. Oh that's not good. Let's get there. Let's get the capitals in the right place. Life lost. So the first thing I want to do with this custom event is get it to update the score and we're just going to take some points away. So what we can do out of a custom event is call another custom event. So we're going to get the update score event and here in this point we can take some away. So let's go minus 500 for now. Let's be really harsh. If they didn't want to lose the points they should have been more careful. What I also want to do now is create a new custom event for game over. So this is what's going to happen when all the lives are gone. So let's go custom event and it's going to be called game over. Good stuff. So this game over event is going to be what we're going to do if the lives is zero or less than zero. So what we'll do then is when we lose a life we need to check was that the last life basically. So let's get how many lives do we have. So we'll get lives and then we need to do a check is this equal to or less than zero and then we'll do a branch out of there because this is our condition on the branch and the question is let's just move these over a little bit. So after we lose a life we update the score take 500 off but then we want to know what's happening with the lives and if it is or equal to zero or less than zero then that will be true and then we're just going to do a game over and that will run our game over script that we will set up. Okay so now we know what's going to happen if this is true if it's false what we're going to want to do is take a life off so our max lives are set to three we're going to need to reduce that by one and we're also going to need to display that on the hood. So the first thing we'll do we'll come out of false then we need to set the current lives so we're going to set lives to whatever our lives was and we're going to take one away from it so let's get lives again and then we're going to do an integer minus integer and we're going to do one so be careful with this one don't put minus one in there because we're already it's a minus operation so we're telling it to take one away and then that's going to go into there so we're setting the lives to lives minus one so that should take three down to two we're also going to get the heads up display and as the heads up display we also want to set points on that as well and that is just going to be the result of that so whatever we've just set the points to set that on the hood as well that should all be good so game over what i need to do for this one is just for now it's kind of a placeholder but we're just going to get it to quit the game so whenever we lose all our lives and game over is called it should just quit the game so let's comment this game over go to the space and we'll comment this with life lost and that should all make sense but even though we put this beautiful script together this life lost script nothing yet is going to call it and that happens in the ball blueprint because that's where the current ball is being destroyed so let's open the BP ball up so here is where um the ball is destroyed new ball when one is destroyed i've got it at the bottom of all my scripts and what i'll do is just create a little bit of new space move these all over to the side a little bit whoosh and then what we need to do is talk to the game mode so let's get the game mode and from the game mode we're going to run life lost like so so let's just connect this in the middle so before it creates a new ball it's going to run this life lost script so now let's give all this a test and see if it's going to behave itself shall we oh right so i'm just going to fire the ball what we're looking for is that the points are removed so it should take 500 points away which is going to set it back to zero here and we lose a life as well that didn't work ah okay i know what i did right silly shame let's go back into the game mode i'm setting points not lives you absolute mug shame delete that lives so we're going to set lives to the result of this okay hopefully this will be more successful now let's compile and test and we'll fire this off so again remove the points hopefully and take a live off we lost all the points we're down to two lives brilliant let's try this again so now we're going to lose more points hopefully and we're going to lose another life yep i will do this one more time and here's the final one does game over work when we lose our last life i'm not doing very well for points on this one am i yay it works okay so that pretty much ties this step up so what we've got working now is both counters lives counters are doing what they should live starts at three goes down to zero and then ends the game the points will go up but every time we lose a ball we're going to lose 500 points you can obviously change the mechanics of that if you want maybe you don't want to be so punishing just take 100 points off maybe you want to start with more or less lives by changing your max lives variable that's totally up to you but that's going to do it for now in the next step we're going to be setting up a game over screen to make it a little bit clearer to the player that the game is in fact over and then we wouldn't quit the application if we were running this on a phone we'd probably return back to a menu screen but we're just going to go probably with game over message and then we'll just reset the game so i'll see you in the next video for that 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