‫Hello and welcome.
‫In this lecture, we're going to be actually restricting the amount of ammo that we have so that once
‫we have used it all up, we can no longer spawn projectiles.
‫I've run out of projectiles and I'm even getting a message saying that I'm out of ammo, I can't spawn
‫anymore.
‫So let's dive in and see how we do this.
‫So ideally what we want to happen is when our ammo goes down to zero, we are no longer able to spawn
‫new projectiles.
‫But how do we control the flow of our code via values in our variables?
‫Well, the solution to this conundrum is something called the branch node.
‫So branches, let us check if something is true or not and then do something based upon the result.
‫So you might have a branch node that looks like this that says If I am hungry, so the condition is
‫I'm hungry, then eat junk food while the wife isn't watching.
‫And if that is not true, then keep playing video games.
‫So these branch nodes allow us to do one thing in if a condition is true and another thing if it is
‫false.
‫Either one of these options could actually not do anything.
‫So you could only connect up the false node, or you could only connect up the true node.
‫Either one of these is going to work.
‫So you'll remember that.
‫Or you you may remember that the color red was associated with boolean type variables in unreal.
‫So let's remind ourselves what is a bull?
‫A bull is short for boolean and there are types that can be store one of two values either true or false,
‫yes or no.
‫They're often used with if statements or branches.
‫So in the future we're going to in C++, we're going to be calling branches if statements.
‫But it's that the same thing, same concept.
‫And they can control whether or not something happens and certain nodes can return booleans.
‫So what kind of nodes could return booleans?
‫What kind of answer do we want?
‫Well, when is it that we want to allow the spawn actor to happen?
‫When do we want a new projectile to be created?
‫We only want a new projectile to be created if the amount of ammo we have is greater than zero.
‫So fortunately, if you right click in your event graph and search for greater, there is a node for
‫that.
‫Is these types of operators or nodes are called comparison because they take in two values and create
‫a comparison between them and allow us to have a boolean answer.
‫So greater is one example, less is another example.
‫You've also can see this less equal, which means it's less than or equal.
‫There's also equal that is it's that is one as well.
‫Equal or not equal.
‫If two values are the same, then return true.
‫Otherwise return false.
‫So let's update our glossary a little bit.
‫We've figured out that a branch is a do something or don't based on a bull.
‫We've figured out that bulls or booleans are a yes no data type, and that comparison is things like
‫less than greater than equal, etc. that crucially return a boolean.
‫So let's have a go at using one of these comparisons.
‫I'm going to right click and add the greater comparison in here.
‫Then I'm going to control click the ammo variable and drag it in to the first node of our comparison
‫node.
‫And then you can see the default here is actually greater than zero.
‫So that's exactly what we want.
‫We've got a node that says Is the ammo greater than zero and the return value is a boolean saying yes
‫if it is and no if it isn't.
‫So what we want to do is take this bool return value, drag off of that and search for branch.
‫Then we can add in a branch node and it automatically connects up the input condition to the boolean
‫that we were dragging.
‫Now I'm going to drag back my space bar event and drag in its pressed node execution pin into the input
‫for the branch.
‫So that's going to execute our branch.
‫Then we want the branch, if it's true, to go ahead and spawn the projectile and otherwise it's going
‫to do nothing.
‫So let's try this out.
‫If we hit play and then we spawn lots of projectiles, we make our projectile value go down to zero.
‫You can see that now, no matter how much I hit the spacebar, I'm not getting any more projectiles.
‫So I'd like to challenge you to print out of ammo.
‫So use the false branch so that we add a print node in there.
‫And basically when we're out of ammo, I would like you to print out of ammo.
‫So test your code and check that that's happening.
‫Pause the video and have a go.
‫Okay.
‫Welcome back.
‫So we've got this second branch of our branch node.
‫Let's just drag this back so we don't get our lines crossing with these execution pins.
‫And the false branch should come down to here where it's going to do a print string.
‫And the string I want it to print is simply going to be out of ammo.
‫Now, if we go ahead and play and fire off all 20 rounds of our cannonball ammo, you can see that each
‫time I hit the spacebar, it just prints out the message that I'm out of ammo, giving the player the
‫indication of why no more balls are spawning into the scene.
‫That's it for this lecture.
‫I will see you in the next one.