Hey there, in this lecture we're gonna implement losing. First of all, I'll open Oh manager. I want to add an alarm event in this object. So I'll go to add event and add the alarm to event. Also as you start here and add the restart game action. The action as the name says restarts the game.
So we'll use this Columbia to restart the game one second after the player dies. Now we'll open our player. I'll go to bootstrap event. Here I'll add an if condition. Make sure you add it below the last action and not inside it. Here I check if the SP is less than or equal to zero, so this means that the player should die.
Now I need to add an alarm action. I'll attach it to the condition. First of all, I'll click on the arrow here and apply this action to or manager. This way I can set an alarm in our manager. So I'll set alarm to which is the alarm that we just added. I'll set it to 60 frames, which would be one second Now we'll search create and add the Create instance action.
For the object, I select Oh explosion. For the position, I'll type x and y and the layer will be instances. So this will create an explosion instance at the player's position. Now I'll add the destroy instance action here to destroy the players instance. So they should destroy the players instance and create an explosion in its place. And after one second, it should restart the game.
So I'll run it and let the player die. You can see that the player does explode, but it throws an error. The error says that it can't find an instance for a player and the error is thrown by Oh enemy, and the event that has the error is the alarm zero event. So since we did destroy our opia instance, the error makes sense. The enemy is dancers can't find a player instance to check if they can shoot so it throws an error. So let's abort the game and fix the bug.
So I'll open Oh enemy and go to it Salaam joy event. Now we'll make it so that if there's no clear instance, the event should be stopped. As you can see, this is what throws the error. Now here also exists, I'll select the instance of this action, I'll drop it at the top of the event. So there's simply checks if an instance exists in the room. So for that, I'll select a player.
So this saxophone player exists in the room, but I want to check if a player does not exist in the room. So for that, I'll take the checkbox. So as you can see in the overview, it checks if a player does not exist in the room. So in that case, we want to exit the event so that the rest of the actions do not run. So in the actions are such exits, I'll select the exit action and attach it to the first condition. So if the player does not exist, it will exit the event.
So this will prevent the next action from throwing an error when the player does not exist. Now run the game and again, let the player die. And you can see that it now works flawlessly. Every time the player dies. The room restarts after one Second. So that's it for this lecture and let's move on to the next one.