﻿1
00:00:04,480 --> 00:00:05,530
‫Hello and welcome.

2
00:00:05,530 --> 00:00:12,040
‫In this lecture, we're going to be actually restricting the amount of ammo that we have so that once

3
00:00:12,040 --> 00:00:16,170
‫we have used it all up, we can no longer spawn projectiles.

4
00:00:16,390 --> 00:00:21,430
‫I've run out of projectiles and I'm even getting a message saying that I'm out of ammo, I can't spawn

5
00:00:21,430 --> 00:00:22,270
‫anymore.

6
00:00:22,270 --> 00:00:24,700
‫So let's dive in and see how we do this.

7
00:00:25,540 --> 00:00:33,430
‫So ideally what we want to happen is when our ammo goes down to zero, we are no longer able to spawn

8
00:00:33,430 --> 00:00:34,930
‫new projectiles.

9
00:00:34,930 --> 00:00:42,760
‫But how do we control the flow of our code via values in our variables?

10
00:00:42,760 --> 00:00:47,170
‫Well, the solution to this conundrum is something called the branch node.

11
00:00:47,170 --> 00:00:54,490
‫So branches, let us check if something is true or not and then do something based upon the result.

12
00:00:54,490 --> 00:01:00,790
‫So you might have a branch node that looks like this that says If I am hungry, so the condition is

13
00:01:00,790 --> 00:01:04,660
‫I'm hungry, then eat junk food while the wife isn't watching.

14
00:01:04,660 --> 00:01:08,470
‫And if that is not true, then keep playing video games.

15
00:01:08,470 --> 00:01:14,500
‫So these branch nodes allow us to do one thing in if a condition is true and another thing if it is

16
00:01:14,500 --> 00:01:15,040
‫false.

17
00:01:15,040 --> 00:01:18,010
‫Either one of these options could actually not do anything.

18
00:01:18,010 --> 00:01:23,080
‫So you could only connect up the false node, or you could only connect up the true node.

19
00:01:23,110 --> 00:01:25,570
‫Either one of these is going to work.

20
00:01:25,570 --> 00:01:27,550
‫So you'll remember that.

21
00:01:27,550 --> 00:01:35,050
‫Or you you may remember that the color red was associated with boolean type variables in unreal.

22
00:01:35,050 --> 00:01:37,660
‫So let's remind ourselves what is a bull?

23
00:01:38,080 --> 00:01:44,320
‫A bull is short for boolean and there are types that can be store one of two values either true or false,

24
00:01:44,320 --> 00:01:45,700
‫yes or no.

25
00:01:45,790 --> 00:01:49,390
‫They're often used with if statements or branches.

26
00:01:49,390 --> 00:01:53,590
‫So in the future we're going to in C++, we're going to be calling branches if statements.

27
00:01:53,590 --> 00:01:56,200
‫But it's that the same thing, same concept.

28
00:01:56,200 --> 00:02:01,870
‫And they can control whether or not something happens and certain nodes can return booleans.

29
00:02:01,870 --> 00:02:04,360
‫So what kind of nodes could return booleans?

30
00:02:04,360 --> 00:02:06,610
‫What kind of answer do we want?

31
00:02:06,610 --> 00:02:13,450
‫Well, when is it that we want to allow the spawn actor to happen?

32
00:02:13,450 --> 00:02:16,600
‫When do we want a new projectile to be created?

33
00:02:16,600 --> 00:02:24,100
‫We only want a new projectile to be created if the amount of ammo we have is greater than zero.

34
00:02:24,100 --> 00:02:31,630
‫So fortunately, if you right click in your event graph and search for greater, there is a node for

35
00:02:31,660 --> 00:02:32,140
‫that.

36
00:02:32,170 --> 00:02:40,660
‫Is these types of operators or nodes are called comparison because they take in two values and create

37
00:02:40,660 --> 00:02:45,070
‫a comparison between them and allow us to have a boolean answer.

38
00:02:45,070 --> 00:02:48,940
‫So greater is one example, less is another example.

39
00:02:48,940 --> 00:02:52,840
‫You've also can see this less equal, which means it's less than or equal.

40
00:02:52,870 --> 00:02:56,890
‫There's also equal that is it's that is one as well.

41
00:02:56,890 --> 00:02:58,570
‫Equal or not equal.

42
00:02:58,570 --> 00:03:01,210
‫If two values are the same, then return true.

43
00:03:01,240 --> 00:03:02,920
‫Otherwise return false.

44
00:03:02,920 --> 00:03:05,020
‫So let's update our glossary a little bit.

45
00:03:05,020 --> 00:03:09,460
‫We've figured out that a branch is a do something or don't based on a bull.

46
00:03:09,460 --> 00:03:15,550
‫We've figured out that bulls or booleans are a yes no data type, and that comparison is things like

47
00:03:15,550 --> 00:03:20,950
‫less than greater than equal, etc. that crucially return a boolean.

48
00:03:20,950 --> 00:03:24,760
‫So let's have a go at using one of these comparisons.

49
00:03:24,760 --> 00:03:30,760
‫I'm going to right click and add the greater comparison in here.

50
00:03:30,760 --> 00:03:36,490
‫Then I'm going to control click the ammo variable and drag it in to the first node of our comparison

51
00:03:36,490 --> 00:03:37,120
‫node.

52
00:03:37,120 --> 00:03:40,870
‫And then you can see the default here is actually greater than zero.

53
00:03:40,870 --> 00:03:42,340
‫So that's exactly what we want.

54
00:03:42,340 --> 00:03:49,480
‫We've got a node that says Is the ammo greater than zero and the return value is a boolean saying yes

55
00:03:49,480 --> 00:03:51,790
‫if it is and no if it isn't.

56
00:03:51,790 --> 00:03:57,610
‫So what we want to do is take this bool return value, drag off of that and search for branch.

57
00:03:57,610 --> 00:04:03,790
‫Then we can add in a branch node and it automatically connects up the input condition to the boolean

58
00:04:03,790 --> 00:04:04,840
‫that we were dragging.

59
00:04:04,840 --> 00:04:14,800
‫Now I'm going to drag back my space bar event and drag in its pressed node execution pin into the input

60
00:04:14,800 --> 00:04:15,550
‫for the branch.

61
00:04:15,550 --> 00:04:18,070
‫So that's going to execute our branch.

62
00:04:18,070 --> 00:04:25,120
‫Then we want the branch, if it's true, to go ahead and spawn the projectile and otherwise it's going

63
00:04:25,120 --> 00:04:26,080
‫to do nothing.

64
00:04:26,080 --> 00:04:27,190
‫So let's try this out.

65
00:04:27,190 --> 00:04:33,310
‫If we hit play and then we spawn lots of projectiles, we make our projectile value go down to zero.

66
00:04:33,310 --> 00:04:40,210
‫You can see that now, no matter how much I hit the spacebar, I'm not getting any more projectiles.

67
00:04:40,210 --> 00:04:43,930
‫So I'd like to challenge you to print out of ammo.

68
00:04:43,930 --> 00:04:49,300
‫So use the false branch so that we add a print node in there.

69
00:04:49,300 --> 00:04:54,310
‫And basically when we're out of ammo, I would like you to print out of ammo.

70
00:04:54,310 --> 00:04:57,040
‫So test your code and check that that's happening.

71
00:04:57,040 --> 00:04:59,200
‫Pause the video and have a go.

72
00:05:02,320 --> 00:05:02,920
‫Okay.

73
00:05:02,920 --> 00:05:03,890
‫Welcome back.

74
00:05:03,910 --> 00:05:09,250
‫So we've got this second branch of our branch node.

75
00:05:09,250 --> 00:05:13,600
‫Let's just drag this back so we don't get our lines crossing with these execution pins.

76
00:05:13,600 --> 00:05:18,220
‫And the false branch should come down to here where it's going to do a print string.

77
00:05:18,220 --> 00:05:23,950
‫And the string I want it to print is simply going to be out of ammo.

78
00:05:23,950 --> 00:05:31,450
‫Now, if we go ahead and play and fire off all 20 rounds of our cannonball ammo, you can see that each

79
00:05:31,450 --> 00:05:37,810
‫time I hit the spacebar, it just prints out the message that I'm out of ammo, giving the player the

80
00:05:37,810 --> 00:05:41,490
‫indication of why no more balls are spawning into the scene.

81
00:05:41,500 --> 00:05:42,790
‫That's it for this lecture.

82
00:05:42,790 --> 00:05:44,320
‫I will see you in the next one.

