﻿1
00:00:04,450 --> 00:00:05,320
‫Hello and welcome.

2
00:00:05,320 --> 00:00:11,200
‫In this lecture, we're going to be learning about Boolean operators so that we can make complicated

3
00:00:11,200 --> 00:00:18,760
‫statements that require multiple booleans to be true, such as having a gargoyle only accepted if it

4
00:00:18,760 --> 00:00:23,470
‫is the correct tag and also it isn't grabbed.

5
00:00:23,470 --> 00:00:29,020
‫So when I let go of the gargoyle, you can see that the wall only responds at that point.

6
00:00:29,020 --> 00:00:31,030
‫Let's dive in and see how this works.

7
00:00:31,990 --> 00:00:40,660
‫So now ideally we would like our trigger component to ignore or not take on an acceptable actor that

8
00:00:40,660 --> 00:00:42,040
‫is currently being grabbed.

9
00:00:42,040 --> 00:00:48,820
‫So to change this, I'm going to go down in to our acceptable actor implementation in trigger component

10
00:00:48,850 --> 00:00:54,880
‫CP and you can see in our if statement we're currently saying let's take an actor if it has the acceptable

11
00:00:54,880 --> 00:00:57,550
‫tag, and that's the only thing we are doing.

12
00:00:57,700 --> 00:01:01,750
‫But what I want to do is make this conditional on two things.

13
00:01:01,750 --> 00:01:04,960
‫How do we combine two Boolean values?

14
00:01:04,960 --> 00:01:06,280
‫Well, there's a couple of options.

15
00:01:06,280 --> 00:01:08,500
‫We've got some operators for this.

16
00:01:08,500 --> 00:01:12,940
‫One of them is the ampersand ampersand operator, which we read as.

17
00:01:12,940 --> 00:01:19,450
‫And and this basically means this will be combined two booleans so that it's only true if both of them

18
00:01:19,450 --> 00:01:20,020
‫are true.

19
00:01:20,350 --> 00:01:27,700
‫So if we had true and true, then that is going to be equal to true.

20
00:01:27,880 --> 00:01:32,950
‫Whereas if either of these is false, so if the one on the right is false, then the whole thing is

21
00:01:32,950 --> 00:01:40,150
‫going to be false, etc. There's another option here, which is to use this double bar operator like

22
00:01:40,150 --> 00:01:44,170
‫so and this one is read as or.

23
00:01:44,170 --> 00:01:49,780
‫And basically this means that if either one of these two is true, then the result will be true.

24
00:01:49,780 --> 00:01:52,510
‫And also, if both of them are true, the result will be true.

25
00:01:52,510 --> 00:01:57,430
‫But if both of them are false, then the result is going to be false.

26
00:01:57,430 --> 00:02:00,520
‫So these are some of the common expressions that we use.

27
00:02:00,520 --> 00:02:08,830
‫One other thing that we use is the exclamation point, and the exclamation point basically inverts whatever

28
00:02:08,830 --> 00:02:11,980
‫boolean value we've got and we read it as not.

29
00:02:11,980 --> 00:02:18,850
‫So you can have false, but because I've put a knot in front of it, this whole value, this expression

30
00:02:18,850 --> 00:02:19,990
‫becomes true.

31
00:02:19,990 --> 00:02:25,870
‫And if I were to order it with false, then well, because one of them at least is true, then the result

32
00:02:25,870 --> 00:02:27,700
‫is going to be true.

33
00:02:28,300 --> 00:02:36,310
‫So what we want to do here is essentially we want to say that if it has an actor tag, that is the acceptable

34
00:02:36,310 --> 00:02:40,210
‫act tag, but it doesn't have.

35
00:02:40,210 --> 00:02:46,300
‫So in this case and it doesn't have the actor tag grabbed then is acceptable.

36
00:02:46,300 --> 00:02:47,980
‫So many challenge for you.

37
00:02:47,980 --> 00:02:52,300
‫How would you use those three operators that I've just explained?

38
00:02:52,300 --> 00:02:57,280
‫You don't have to use all of them, but which ones would you use and how would you write out this if

39
00:02:57,280 --> 00:02:58,060
‫statement?

40
00:03:00,110 --> 00:03:00,350
‫Okay.

41
00:03:00,380 --> 00:03:03,380
‫So I'm going to put this into Boolean variables to make it super clear.

42
00:03:03,380 --> 00:03:15,800
‫So you've got bool that has acceptable tag is going to be equal to actor has tag acceptable tag like

43
00:03:15,800 --> 00:03:17,870
‫so and put a semicolon on the end of the line.

44
00:03:17,870 --> 00:03:27,770
‫Now another bool is going to be whether it is grabbed and we can get this by going actor arrow actor

45
00:03:27,950 --> 00:03:35,240
‫has tag and this case it's just going to be grabbed like so so we can say that whether it's grabbed

46
00:03:35,240 --> 00:03:44,420
‫or not on this basis then in the if what we want to say is has acceptable tag and so that's ampersand

47
00:03:44,420 --> 00:03:54,560
‫ampersand not that's an exclamation point is grabbed like so so that reads fairly well if you read out

48
00:03:54,560 --> 00:04:02,690
‫the ampersand and the exclamation point as and and not so if acceptable has acceptable tag and not is

49
00:04:02,690 --> 00:04:05,770
‫grabbed, then we return this actor.

50
00:04:05,780 --> 00:04:08,240
‫Let's compile it and see if it works.

51
00:04:08,240 --> 00:04:10,130
‫So let's go ahead and hit play.

52
00:04:10,160 --> 00:04:15,140
‫We'll grab our gargoyle and run over to the trigger area.

53
00:04:15,230 --> 00:04:20,600
‫And you see, I'm putting the gargoyle in, but nothing is happening because I've not released it yet.

54
00:04:20,600 --> 00:04:23,420
‫So what if I try and pop the gargoyle down here?

55
00:04:23,450 --> 00:04:23,840
‫There you go.

56
00:04:23,840 --> 00:04:29,660
‫As soon as I release it, it activates it, grabs the gargoyle away from me and it disappears into the

57
00:04:29,660 --> 00:04:30,270
‫ground.

58
00:04:30,290 --> 00:04:38,000
‫Now there are a couple of places in Grab a CP where we've got two if statements where we could just

59
00:04:38,000 --> 00:04:43,670
‫have one if we were to use the and or and not operated.

60
00:04:43,670 --> 00:04:48,980
‫So one of the trick here is that when you're doing something like this where we're checking whether

61
00:04:48,980 --> 00:04:55,280
‫something is not a null pointer, the other option is you can simply remove this not equal to null pointer.

62
00:04:55,280 --> 00:05:04,220
‫And if you simply say if and then put in some sort of pointer as the boolean, then that automatically

63
00:05:04,220 --> 00:05:06,620
‫checks that it isn't a null pointer.

64
00:05:06,620 --> 00:05:13,970
‫So here it's saying if the physics handle is available here, it's saying if the grab component is available,

65
00:05:13,970 --> 00:05:16,460
‫then we can go ahead and use it.

66
00:05:16,460 --> 00:05:19,400
‫So I'd like to challenge you to combine your if statements.

67
00:05:19,400 --> 00:05:22,340
‫So you're going to join them together in tick components.

68
00:05:22,340 --> 00:05:28,190
‫Think about whether you need to use the ampersand, ampersand, the and the OR or whether you need to

69
00:05:28,190 --> 00:05:35,240
‫use a negation or a knot or an exclamation point and then join them together in release as well and

70
00:05:35,240 --> 00:05:37,710
‫test out your functionality and see if it still works.

71
00:05:37,730 --> 00:05:39,800
‫Pause the video and have a go.

72
00:05:42,930 --> 00:05:43,380
‫Okay.

73
00:05:43,380 --> 00:05:44,070
‫Welcome back.

74
00:05:44,070 --> 00:05:50,040
‫So we're going to make use of this because basically what we want to be doing in release is we're saying

75
00:05:50,040 --> 00:05:57,600
‫if we have got a valid physics handle and that physics handle has got a grabbed component, then we

76
00:05:57,600 --> 00:06:00,240
‫want to do the body of this if statement.

77
00:06:00,240 --> 00:06:03,000
‫So it's quite simple to write it like that.

78
00:06:03,000 --> 00:06:12,240
‫We can say if physics handle and physics handle get grabbed component, then we can do the following.

79
00:06:12,240 --> 00:06:18,600
‫So that allows us to remove this early return if statement and make the code a little bit shorter.

80
00:06:18,870 --> 00:06:26,400
‫Now, the eagle eyed among you may worry that, hey, we are referencing this physics handle inside

81
00:06:26,400 --> 00:06:32,340
‫the if statement in order to evaluate whether this and statement should work.

82
00:06:32,760 --> 00:06:38,550
‫Now there is a feature of the and that it will evaluate the thing on the left first.

83
00:06:38,550 --> 00:06:43,920
‫And if that thing is false, then it doesn't even evaluate the thing on the right.

84
00:06:43,920 --> 00:06:44,820
‫It doesn't need to.

85
00:06:44,850 --> 00:06:47,580
‫It already knows that the result is going to be false.

86
00:06:47,580 --> 00:06:50,130
‫It doesn't need to evaluate anything any further.

87
00:06:50,130 --> 00:06:57,090
‫So that means it is safe to do something like this where the result on the right to calculate it is

88
00:06:57,090 --> 00:07:01,500
‫only safe to do if the result on the left is true.

89
00:07:01,890 --> 00:07:06,810
‫And this is quite a handy property and you'll see this used quite a lot when you are using pointers

90
00:07:06,810 --> 00:07:10,320
‫that first you will check the pointer and then you'll have an ampersand.

91
00:07:10,320 --> 00:07:13,860
‫Ampersand, and then you will use the pointer in the right hand side.

92
00:07:13,860 --> 00:07:18,660
‫But please, please, please don't be tempted to swap these two around in order.

93
00:07:18,660 --> 00:07:22,950
‫It will not work the other way around and you will get crashes.

94
00:07:22,950 --> 00:07:28,080
‫So let's go up to our tick component where we're essentially doing exactly the same thing.

95
00:07:28,080 --> 00:07:30,720
‫We wanted to check that we've got a grabbed component.

96
00:07:30,720 --> 00:07:37,200
‫So what we can do up here is we can do physics handle and physics handle.

97
00:07:37,470 --> 00:07:38,940
‫Arrow grabbed component.

98
00:07:38,940 --> 00:07:44,430
‫We don't need that not equal to null pointer to keep it neat and then we can go ahead and remove the

99
00:07:44,430 --> 00:07:49,770
‫if statement with the return and just keep the lines of code down, keep the legibility a little bit

100
00:07:49,770 --> 00:07:50,430
‫higher.

101
00:07:50,460 --> 00:07:50,970
‫Great stuff.

102
00:07:50,970 --> 00:07:57,480
‫So in this lecture we've seen how to use the and or and not operators in C++.

103
00:07:57,480 --> 00:07:58,980
‫I'll see you in the next lecture.

