1
00:00:00,000 --> 00:00:03,540
Welcome back my fellow game developers

2
00:00:03,540 --> 00:00:06,260
to a brand new long video.

3
00:00:06,255 --> 00:00:08,195
We are not going to waste any time.

4
00:00:08,190 --> 00:00:11,340
And this video, what we do is when we kill the enemies,

5
00:00:11,340 --> 00:00:12,450
this is not very exciting.

6
00:00:12,450 --> 00:00:14,300
I'll just tell you, when we kill the enemies,

7
00:00:14,295 --> 00:00:15,875
we pick two random numbers.

8
00:00:15,870 --> 00:00:16,550
That's it.

9
00:00:16,545 --> 00:00:17,885
That's all that we do.

10
00:00:17,880 --> 00:00:19,800
Next video, you'll see why,

11
00:00:19,800 --> 00:00:22,110
but it's a pretty complicated concept

12
00:00:22,110 --> 00:00:24,530
where we learn a new kind of loop.

13
00:00:24,525 --> 00:00:26,255
We learned the truth tables.

14
00:00:26,250 --> 00:00:28,920
So it's very, very worth it.

15
00:00:28,920 --> 00:00:33,120
So that's not waste any more time and let's get started.

16
00:00:33,120 --> 00:00:34,950
Oh, case.

17
00:00:34,950 --> 00:00:37,730
So now we are completing the waves.

18
00:00:37,725 --> 00:00:41,125
It's time to leave the room and go to the next one.

19
00:00:41,125 --> 00:00:43,615
So how are we going to do this?

20
00:00:43,610 --> 00:00:46,810
Let's just take a brief moment to talk about that.

21
00:00:46,805 --> 00:00:49,885
We're going to go into the rooms, the doors.

22
00:00:49,880 --> 00:00:51,200
And as you can see, we have

23
00:00:51,200 --> 00:00:53,690
two doors with two portals behind them.

24
00:00:53,690 --> 00:00:55,400
And this is something that will be the

25
00:00:55,400 --> 00:00:57,400
same in every single level.

26
00:00:57,395 --> 00:01:00,065
I didn't want to add too much thing just to keep

27
00:01:00,065 --> 00:01:03,325
everything less complicated and understandable.

28
00:01:03,320 --> 00:01:04,850
So what we have in here are

29
00:01:04,850 --> 00:01:07,450
the two portals and the two doors.

30
00:01:07,445 --> 00:01:09,775
So what happens when we kill

31
00:01:09,770 --> 00:01:13,990
all the waves or all the enemies in the last wave,

32
00:01:13,985 --> 00:01:18,575
wave, these doors will have the ability to open up.

33
00:01:18,575 --> 00:01:22,055
But as you saw in the game Hades,

34
00:01:22,055 --> 00:01:23,665
we have always two options.

35
00:01:23,660 --> 00:01:26,960
So we have two portals that we can go through 14,

36
00:01:26,960 --> 00:01:28,430
let's say the sharp, the other one

37
00:01:28,430 --> 00:01:30,310
to another enemy arena.

38
00:01:30,305 --> 00:01:32,455
And that's what we want to also do.

39
00:01:32,450 --> 00:01:36,080
We want to have the option to go to one of these two?

40
00:01:36,080 --> 00:01:38,630
So we'll need to set these two portals

41
00:01:38,630 --> 00:01:42,190
beforehand and these two doors also beforehand.

42
00:01:42,185 --> 00:01:44,845
Later on we will be creating maybe some kind

43
00:01:44,840 --> 00:01:49,370
of maybe name appearing once we are next to the door.

44
00:01:49,370 --> 00:01:52,130
So when we open it, we know where we are going.

45
00:01:52,130 --> 00:01:56,950
But for now, let's just focus on actually changing The,

46
00:01:56,945 --> 00:02:00,005
whereas if we click on the Portal and unlock this,

47
00:02:00,005 --> 00:02:01,765
you can see that we have the level 2

48
00:02:01,760 --> 00:02:03,980
goes or the level to load.

49
00:02:03,980 --> 00:02:06,050
So what we'll do is we'll try to

50
00:02:06,050 --> 00:02:08,960
change these as soon as we kill the enemies.

51
00:02:08,960 --> 00:02:10,670
So let's get started.

52
00:02:10,670 --> 00:02:12,410
I'm going to go back into

53
00:02:12,410 --> 00:02:14,300
our code and the first thing I will

54
00:02:14,300 --> 00:02:17,990
do is I'm going to go into the level of exit in here.

55
00:02:17,990 --> 00:02:19,940
And instead of using a string,

56
00:02:19,940 --> 00:02:23,380
we are going to be using a integer.

57
00:02:23,375 --> 00:02:24,785
So an integer.

58
00:02:24,785 --> 00:02:27,125
Why are we working with integers?

59
00:02:27,125 --> 00:02:29,485
Well, because in here we will be

60
00:02:29,480 --> 00:02:31,940
using several methods in the scene manager

61
00:02:31,940 --> 00:02:33,650
that can only taken

62
00:02:33,650 --> 00:02:36,910
an integer parameter that we can work with.

63
00:02:36,905 --> 00:02:39,605
So that's why we are changing it to endanger.

64
00:02:39,605 --> 00:02:42,575
Later on you'll see why all of this is happening.

65
00:02:42,575 --> 00:02:45,205
I'm going to make sure that this is

66
00:02:45,200 --> 00:02:46,370
commented out and we'll

67
00:02:46,370 --> 00:02:47,960
later on we'll come back and change it.

68
00:02:47,960 --> 00:02:50,420
But for now because the loading level is

69
00:02:50,420 --> 00:02:53,450
taking in an integer or you know what, let's keep it.

70
00:02:53,450 --> 00:02:55,790
And let's keep it.

71
00:02:55,790 --> 00:02:57,730
And let's go to the level manager.

72
00:02:57,725 --> 00:02:59,875
And in the loading next level,

73
00:02:59,870 --> 00:03:00,890
instead of a string,

74
00:03:00,890 --> 00:03:03,400
we are going to use an integer.

75
00:03:03,395 --> 00:03:05,705
So the next level is an integer,

76
00:03:05,705 --> 00:03:07,505
and the load scene can actually

77
00:03:07,505 --> 00:03:09,875
take an integer as a parameter.

78
00:03:09,875 --> 00:03:12,205
So everything is working good for now.

79
00:03:12,200 --> 00:03:14,720
The next thing we need to do is we need to set

80
00:03:14,720 --> 00:03:17,500
the two doors or the two-level exits.

81
00:03:17,495 --> 00:03:20,165
And because we already have everything

82
00:03:20,165 --> 00:03:23,435
set up and we know that there will always be two doors.

83
00:03:23,435 --> 00:03:25,045
To just make simple,

84
00:03:25,040 --> 00:03:26,060
I'm going to create

85
00:03:26,060 --> 00:03:31,960
a public and level level

86
00:03:31,955 --> 00:03:37,115
to go to underscore one.

87
00:03:37,115 --> 00:03:39,535
And then I'm going to copy this

88
00:03:39,530 --> 00:03:41,510
and make it the underscore two.

89
00:03:41,510 --> 00:03:43,850
So this is for the second level.

90
00:03:43,850 --> 00:03:49,340
And then I'm also going to create a public level exit.

91
00:03:49,340 --> 00:03:53,330
And this will be the level exit underscore

92
00:03:53,330 --> 00:03:59,240
one and the level exit underscore two.

93
00:03:59,240 --> 00:04:02,060
So now we have the two level exit strategy

94
00:04:02,060 --> 00:04:04,700
and let's go ahead and create a level picker.

95
00:04:04,700 --> 00:04:07,040
So I'm going to scroll down,

96
00:04:07,039 --> 00:04:09,199
but not too much, maybe right here.

97
00:04:09,200 --> 00:04:11,330
And I'm going to say that I have

98
00:04:11,330 --> 00:04:18,880
a public void level picker.

99
00:04:18,875 --> 00:04:20,935
And in here we are going to be

100
00:04:20,930 --> 00:04:23,080
employing a couple of things.

101
00:04:23,075 --> 00:04:27,535
So what we want to do is we want to pick a level.

102
00:04:27,530 --> 00:04:32,410
But that's not as simple as you might think because we,

103
00:04:32,405 --> 00:04:34,925
let say we are currently on the skeleton level.

104
00:04:34,925 --> 00:04:36,565
This Kelly's. Okay.

105
00:04:36,560 --> 00:04:39,200
Let's say we have the option to go,

106
00:04:39,200 --> 00:04:40,360
for example, to the shop.

107
00:04:40,355 --> 00:04:41,635
One of them will be the shop.

108
00:04:41,630 --> 00:04:44,140
We will try to choose a random level.

109
00:04:44,135 --> 00:04:47,335
So we have the option to go to the top on the first door,

110
00:04:47,330 --> 00:04:50,660
but on the second door we get the option to go

111
00:04:50,660 --> 00:04:54,200
to the skull is but we've already been in the Skelly.

112
00:04:54,200 --> 00:04:57,590
So the thing that we need to keep in mind is that every

113
00:04:57,590 --> 00:05:01,120
time we want to have the option to choose another level,

114
00:05:01,115 --> 00:05:03,095
it has to be different

115
00:05:03,094 --> 00:05:05,374
than the current level that we're on.

116
00:05:05,375 --> 00:05:06,745
And not only that,

117
00:05:06,740 --> 00:05:09,640
we need to also have the level.

118
00:05:09,635 --> 00:05:11,425
On the left door different

119
00:05:11,420 --> 00:05:13,180
than the level on the right door.

120
00:05:13,175 --> 00:05:17,795
So essentially, we need three things to keep track of.

121
00:05:17,795 --> 00:05:19,475
The level we're currently on.

122
00:05:19,475 --> 00:05:22,975
The level that will go to if we go through the first door

123
00:05:22,970 --> 00:05:24,730
and the level will go to if we

124
00:05:24,725 --> 00:05:26,875
go through the second door.

125
00:05:26,870 --> 00:05:28,750
So how are we going to do this?

126
00:05:28,745 --> 00:05:30,865
How are we going to implement this?

127
00:05:30,860 --> 00:05:35,630
Finding things while we are still on the same level?

128
00:05:35,630 --> 00:05:39,290
This is where we will use something called a while loop.

129
00:05:39,290 --> 00:05:42,400
So let me tell you what a while loop is and you'll see

130
00:05:42,395 --> 00:05:45,745
how important it is in this situation right here.

131
00:05:45,740 --> 00:05:48,440
So first of all, it's similar to for loops at

132
00:05:48,440 --> 00:05:51,670
executes a block of code a number of times.

133
00:05:51,665 --> 00:05:55,285
Instead of determining the number of times before hand,

134
00:05:55,280 --> 00:05:58,310
we wait until a certain condition is met.

135
00:05:58,310 --> 00:06:01,220
So this is perfect for our case right here,

136
00:06:01,220 --> 00:06:03,920
because we don't know how many times we have

137
00:06:03,920 --> 00:06:06,740
to go through looking for a level,

138
00:06:06,740 --> 00:06:10,930
but we know that we will keep looking while

139
00:06:10,925 --> 00:06:12,595
the level that we want to set on

140
00:06:12,590 --> 00:06:15,340
the first door is different than the current level.

141
00:06:15,335 --> 00:06:18,065
And we will also keep looking while

142
00:06:18,065 --> 00:06:19,825
the second level on

143
00:06:19,820 --> 00:06:22,490
the second door is different than the first one,

144
00:06:22,490 --> 00:06:24,470
which is already and

145
00:06:24,470 --> 00:06:27,500
different than the level we are currently on.

146
00:06:27,500 --> 00:06:29,000
So let me just take you through

147
00:06:29,000 --> 00:06:30,790
the structure of the for loop.

148
00:06:30,785 --> 00:06:32,065
You can see right here,

149
00:06:32,060 --> 00:06:33,590
we have the while.

150
00:06:33,590 --> 00:06:35,380
We open up the brackets,

151
00:06:35,375 --> 00:06:37,025
we put in a condition.

152
00:06:37,025 --> 00:06:39,545
It's exactly the same as the if statement.

153
00:06:39,545 --> 00:06:40,805
And if it is true,

154
00:06:40,805 --> 00:06:43,525
then we will do something called execute and then

155
00:06:43,520 --> 00:06:46,420
go back to the condition, condition change.

156
00:06:46,415 --> 00:06:48,295
If it hasn't, we go back.

157
00:06:48,290 --> 00:06:51,650
So make sure to take precaution whenever using while

158
00:06:51,650 --> 00:06:55,220
loops because they can cause a lot of problems.

159
00:06:55,220 --> 00:06:57,350
You can end up in a endless loop where

160
00:06:57,350 --> 00:07:00,580
the condition doesn't change and your Unity will crash.

161
00:07:00,575 --> 00:07:02,995
Trust me, it happens and happens to me

162
00:07:02,990 --> 00:07:05,470
all the time whenever I'm using while loops.

163
00:07:05,465 --> 00:07:08,215
So make sure you know the problem.

164
00:07:08,210 --> 00:07:10,520
Make sure you always change

165
00:07:10,520 --> 00:07:13,370
the condition and always get out of the while loop.

166
00:07:13,370 --> 00:07:14,570
Anyways, with that said,

167
00:07:14,570 --> 00:07:16,400
let's go back to Unity.

168
00:07:16,400 --> 00:07:18,470
And here, I mean Visual Studio.

169
00:07:18,470 --> 00:07:20,320
And what are we going to do in here?

170
00:07:20,315 --> 00:07:24,745
We are going to say that while level to go

171
00:07:24,740 --> 00:07:29,630
to one is equal to the scene manager,

172
00:07:29,630 --> 00:07:37,420
dot, get active, seen dot index.

173
00:07:37,415 --> 00:07:41,275
Then we are going to go ahead and create

174
00:07:41,270 --> 00:07:45,260
a random random number which is

175
00:07:45,260 --> 00:07:52,390
equal to a random dot range from 0 or actually from one.

176
00:07:52,385 --> 00:07:53,605
What are we using one?

177
00:07:53,600 --> 00:07:56,480
Well, because we know that the scene on index

178
00:07:56,480 --> 00:07:59,810
0 is not something that we would like to go to.

179
00:07:59,810 --> 00:08:01,270
Let me show you what I mean.

180
00:08:01,265 --> 00:08:03,095
If I go back into the File,

181
00:08:03,095 --> 00:08:06,265
BuildSettings, the first one as the title screen,

182
00:08:06,260 --> 00:08:08,330
the new weapon spikes and everything

183
00:08:08,330 --> 00:08:11,110
is available except for the 0,

184
00:08:11,105 --> 00:08:13,505
which, and the, obviously the last one.

185
00:08:13,505 --> 00:08:16,415
So in here, the random we'll start at one.

186
00:08:16,415 --> 00:08:20,245
So from one to the scene manager,

187
00:08:20,240 --> 00:08:24,110
the scene count in Build Settings.

188
00:08:24,110 --> 00:08:25,940
And you can see right here, this is the number

189
00:08:25,940 --> 00:08:28,000
of scenes and the build settings.

190
00:08:27,995 --> 00:08:30,875
And we are going to reduce it by one,

191
00:08:30,875 --> 00:08:34,645
because obviously we don't want the last one in there.

192
00:08:34,640 --> 00:08:37,870
So now that we have a random number of our scenes,

193
00:08:37,865 --> 00:08:41,705
I'm just going to go ahead and print that random number.

194
00:08:41,705 --> 00:08:51,845
So print and let's say the room for the random number,

195
00:08:51,845 --> 00:08:57,935
random number is and first round.

196
00:08:57,935 --> 00:09:00,955
And then in here we are going to set the level

197
00:09:00,950 --> 00:09:04,100
to go one to be equal to rant.

198
00:09:04,100 --> 00:09:07,070
Okay, so what's happening in here?

199
00:09:07,070 --> 00:09:10,490
First of all, we say that while the level to

200
00:09:10,490 --> 00:09:15,320
go is equal to the current build index,

201
00:09:15,319 --> 00:09:17,959
then we are going to enter the while loop,

202
00:09:17,960 --> 00:09:19,940
chosen random number assigned

203
00:09:19,940 --> 00:09:22,310
the level to go if it's still the same,

204
00:09:22,310 --> 00:09:23,890
and then check the condition in here.

205
00:09:23,885 --> 00:09:25,225
If it's still the same,

206
00:09:25,220 --> 00:09:26,750
then again we will create

207
00:09:26,750 --> 00:09:29,830
another random number and assign it to the level to go.

208
00:09:29,825 --> 00:09:31,435
And we will keep doing this.

209
00:09:31,430 --> 00:09:35,270
While the level to go 1 is equal to

210
00:09:35,270 --> 00:09:37,550
the scene manager or the build index

211
00:09:37,550 --> 00:09:40,120
of the scene that is active right now.

212
00:09:40,115 --> 00:09:43,945
Once It's not, once this condition is no longer met,

213
00:09:43,940 --> 00:09:46,850
we will continue on to setting over things.

214
00:09:46,850 --> 00:09:48,290
Before we continue.

215
00:09:48,290 --> 00:09:51,860
Obviously, we need to do something which is set the level

216
00:09:51,860 --> 00:09:55,990
to go one to be equal to the scene manager.

217
00:09:55,985 --> 00:09:59,255
The just copy this one.

218
00:09:59,255 --> 00:10:01,075
So we're just sending it at

219
00:10:01,070 --> 00:10:02,870
the beginning as this one just so we

220
00:10:02,870 --> 00:10:06,250
can enter into the loop and then continue on.

221
00:10:06,245 --> 00:10:07,745
So let's save that.

222
00:10:07,745 --> 00:10:11,545
Let's go back into our gain o and we actually.

223
00:10:11,540 --> 00:10:13,100
We haven't got this yet.

224
00:10:13,100 --> 00:10:14,420
So to call this,

225
00:10:14,420 --> 00:10:15,850
where should we be calling it?

226
00:10:15,845 --> 00:10:18,245
I believe this is part of your challenge.

227
00:10:18,245 --> 00:10:21,745
Well, I think it will be part of your challenge.

228
00:10:21,740 --> 00:10:24,790
So unfortunately we will not be able to test it.

229
00:10:24,785 --> 00:10:26,485
But, or you know what,

230
00:10:26,480 --> 00:10:27,710
let's test it out.

231
00:10:27,710 --> 00:10:31,730
So if I go to where do you think if you want to,

232
00:10:31,730 --> 00:10:33,290
you can make it a challenge.

233
00:10:33,290 --> 00:10:35,830
But unfortunately, I've already shown you.

234
00:10:35,825 --> 00:10:39,485
So in here when we said the debug,

235
00:10:39,485 --> 00:10:40,735
all waves are complete.

236
00:10:40,730 --> 00:10:42,080
Let's just keep this,

237
00:10:42,080 --> 00:10:44,540
remove the common because now we can

238
00:10:44,540 --> 00:10:47,200
actually go ahead and access the level manager.

239
00:10:47,195 --> 00:10:49,315
And I believe it is an instance.

240
00:10:49,310 --> 00:10:53,260
And we will access the level picker.

241
00:10:53,255 --> 00:10:56,885
And now we can actually pick a level and we

242
00:10:56,885 --> 00:11:00,425
should also make sure that the waves are complete.

243
00:11:00,425 --> 00:11:02,185
And we also need to make sure that

244
00:11:02,180 --> 00:11:03,900
the waves are complete.

245
00:11:03,904 --> 00:11:06,204
So how are we going to do this?

246
00:11:06,200 --> 00:11:07,580
This is something we should have

247
00:11:07,580 --> 00:11:09,340
done prior, but no worries.

248
00:11:09,335 --> 00:11:11,995
We are going to create a private variable in

249
00:11:11,990 --> 00:11:16,470
here and waves complete.

250
00:11:17,020 --> 00:11:21,050
And we will set it as false at the beginning.

251
00:11:21,050 --> 00:11:26,570
So private, oh, sorry, Boolean waves complete.

252
00:11:26,570 --> 00:11:28,790
And where do we set it to true?

253
00:11:28,790 --> 00:11:31,700
Down here after all the waves are complete.

254
00:11:31,700 --> 00:11:35,600
So waves complete is equal to true.

255
00:11:35,600 --> 00:11:38,240
And where does this affect everything?

256
00:11:38,240 --> 00:11:39,950
Well, up here, if we

257
00:11:39,950 --> 00:11:42,830
look where we are spawning every single time.

258
00:11:42,830 --> 00:11:45,530
So I'm going to indent this using the tab.

259
00:11:45,530 --> 00:11:48,700
And I'm going to say if waves are

260
00:11:48,695 --> 00:11:52,325
not complete yet, so, right?

261
00:11:52,325 --> 00:11:57,565
Waves complete are not yet complete.

262
00:11:57,560 --> 00:11:59,570
So if this one is still false,

263
00:11:59,570 --> 00:12:01,640
which it shouldn't be false until we

264
00:12:01,640 --> 00:12:04,060
turn into true right here.

265
00:12:04,055 --> 00:12:07,445
So as this keep it as that,

266
00:12:07,445 --> 00:12:08,545
I believe this will work,

267
00:12:08,540 --> 00:12:09,890
but you know what, I'm going to

268
00:12:09,890 --> 00:12:11,720
add the two squiggly lines,

269
00:12:11,720 --> 00:12:13,980
make sure everything is set up properly.

270
00:12:13,984 --> 00:12:17,644
So now, once we destroy or finish all the waves,

271
00:12:17,645 --> 00:12:19,235
Waves complete is done.

272
00:12:19,235 --> 00:12:24,445
We are no longer counting down and we choose a level.

273
00:12:24,440 --> 00:12:27,200
So we'll try to see how that looks in our game.

274
00:12:27,200 --> 00:12:29,650
So we run.

275
00:12:29,645 --> 00:12:31,825
And I believe we should remove

276
00:12:31,820 --> 00:12:34,730
the just to make it faster.

277
00:12:34,730 --> 00:12:38,830
So I'm going to shoot the enemies couple of times.

278
00:12:38,825 --> 00:12:40,595
Wait for the second wave,

279
00:12:40,595 --> 00:12:44,315
which are the cowardly find eyes.

280
00:12:44,315 --> 00:12:47,635
I'm going to shoot the cowardly flying eyes.

281
00:12:47,630 --> 00:12:49,280
And there we go.

282
00:12:49,280 --> 00:12:51,050
And we have one still here.

283
00:12:51,050 --> 00:12:52,400
So once we kill it,

284
00:12:52,400 --> 00:12:54,260
we have the random number three.

285
00:12:54,260 --> 00:12:56,810
And let's open up the console and pause the game.

286
00:12:56,810 --> 00:12:58,490
So if we look in the console,

287
00:12:58,490 --> 00:13:01,220
we have the random number is three.

288
00:13:01,220 --> 00:13:04,400
So obviously this work for the first time.

289
00:13:04,400 --> 00:13:07,160
Let's see what the build index 40s,

290
00:13:07,160 --> 00:13:08,920
Kelly's are, its two.

291
00:13:08,915 --> 00:13:11,555
So three is the boss level.

292
00:13:11,555 --> 00:13:14,155
So we chose another level.

293
00:13:14,150 --> 00:13:14,710
Excellent.

294
00:13:14,705 --> 00:13:16,535
I really want for you to see

295
00:13:16,535 --> 00:13:19,915
the random number being chosen multiple times,

296
00:13:19,910 --> 00:13:21,980
but no worries, we will have a lot of

297
00:13:21,980 --> 00:13:24,530
opportunity for those things.

298
00:13:24,530 --> 00:13:26,420
I'm going to remove this one in

299
00:13:26,420 --> 00:13:28,670
here and the debug right here,

300
00:13:28,670 --> 00:13:30,670
because we already know everything

301
00:13:30,665 --> 00:13:33,295
is working perfectly fine.

302
00:13:33,290 --> 00:13:35,330
But there is obviously

303
00:13:35,330 --> 00:13:37,690
still the second level that we want to set.

304
00:13:37,685 --> 00:13:41,615
So I'm going to issue it to you as a challenge.

305
00:13:41,615 --> 00:13:45,305
And your challenge is to set the level to go to,

306
00:13:45,305 --> 00:13:47,705
to get it pun intended.

307
00:13:47,705 --> 00:13:50,975
So after setting the first-level to go to,

308
00:13:50,975 --> 00:13:53,065
we need to set the second one.

309
00:13:53,060 --> 00:13:54,710
And the second one should be

310
00:13:54,710 --> 00:13:57,190
different than the first level.

311
00:13:57,185 --> 00:13:59,455
And the first-level to go

312
00:13:59,450 --> 00:14:01,990
to and the one we are currently on.

313
00:14:01,985 --> 00:14:05,255
So you'll need to make sure to initialize it.

314
00:14:05,255 --> 00:14:07,585
And I'm going to give you a hint because

315
00:14:07,580 --> 00:14:09,560
we want to make sure that it's different

316
00:14:09,560 --> 00:14:11,270
than the first one and

317
00:14:11,270 --> 00:14:13,960
different than the one we are currently on.

318
00:14:13,955 --> 00:14:16,325
You'll need to use the OR

319
00:14:16,325 --> 00:14:18,355
for the while condition to stop.

320
00:14:18,350 --> 00:14:21,140
And I haven't shown you the sea yet,

321
00:14:21,140 --> 00:14:23,380
so I'm going to show it to you right here.

322
00:14:23,375 --> 00:14:25,465
If you want, you can maybe, I don't know,

323
00:14:25,460 --> 00:14:27,500
take a screenshot or maybe then go back

324
00:14:27,500 --> 00:14:29,630
and see the whole steps of the challenge.

325
00:14:29,630 --> 00:14:31,450
I'm going to now show you

326
00:14:31,445 --> 00:14:35,525
the truth table and the truth table.

327
00:14:35,525 --> 00:14:36,955
So let's start with the end.

328
00:14:36,950 --> 00:14:38,450
So the end a truth table.

329
00:14:38,450 --> 00:14:39,560
How does it work?

330
00:14:39,560 --> 00:14:41,660
If we have several conditions,

331
00:14:41,660 --> 00:14:43,100
as I've said right now,

332
00:14:43,100 --> 00:14:45,400
we need to make sure that it's different than

333
00:14:45,395 --> 00:14:47,335
the current level and

334
00:14:47,330 --> 00:14:49,100
different than the first one we've set.

335
00:14:49,100 --> 00:14:52,430
So it has to be a while loop which checks

336
00:14:52,430 --> 00:14:55,910
for using the all so while level

337
00:14:55,910 --> 00:14:59,360
two that we're going to set is

338
00:14:59,360 --> 00:15:04,520
equal to love and want to go or level two to go,

339
00:15:04,520 --> 00:15:06,320
then we will need to change it.

340
00:15:06,320 --> 00:15:08,200
It needs to be different than both.

341
00:15:08,195 --> 00:15:10,555
So let me show you how the true,

342
00:15:10,550 --> 00:15:12,320
the truth table works.

343
00:15:12,320 --> 00:15:14,440
If you have two true, we get a true.

344
00:15:14,435 --> 00:15:17,675
If we have a false and a true, we get a false.

345
00:15:17,675 --> 00:15:20,365
If we have a false and a false, we get a false,

346
00:15:20,360 --> 00:15:21,970
we have a true and a false,

347
00:15:21,965 --> 00:15:23,705
we get a false.

348
00:15:23,705 --> 00:15:25,865
But when it comes to the, OR,

349
00:15:25,865 --> 00:15:30,145
you'll see that if we have one false and one true, then.

350
00:15:30,140 --> 00:15:32,320
Answer will be true,

351
00:15:32,315 --> 00:15:34,675
but if both of them are false,

352
00:15:34,670 --> 00:15:37,060
then the answer will be false.

353
00:15:37,055 --> 00:15:39,215
So with that information,

354
00:15:39,215 --> 00:15:41,525
I know it's a bit confusing now when we

355
00:15:41,525 --> 00:15:43,865
do actually have the solution for the challenge,

356
00:15:43,865 --> 00:15:45,575
I will explain to you everything,

357
00:15:45,575 --> 00:15:47,945
even though this video is getting very long,

358
00:15:47,945 --> 00:15:49,315
but no worries about that.

359
00:15:49,310 --> 00:15:53,740
Pause the video right now and go do the challenge.

360
00:15:53,735 --> 00:15:55,855
Okay, welcome back.

361
00:15:55,850 --> 00:15:57,710
How did you get on with that?

362
00:15:57,710 --> 00:15:59,500
So in the level manager,

363
00:15:59,495 --> 00:16:01,855
I know this is one of the tougher challenges,

364
00:16:01,850 --> 00:16:04,540
but we are in the Advanced Challenge.

365
00:16:04,535 --> 00:16:10,525
So in here I'm going to say that the wild and level 2,

366
00:16:10,520 --> 00:16:19,330
oops, the level to go to is equal to the level to go one.

367
00:16:19,330 --> 00:16:24,000
Or how's the, or it's these two columns,

368
00:16:23,995 --> 00:16:27,085
or the level to go to is

369
00:16:27,085 --> 00:16:31,215
equal to the scene manager dot index.

370
00:16:31,210 --> 00:16:33,470
So the current one.

371
00:16:34,410 --> 00:16:37,860
Then in here we are going to go ahead

372
00:16:37,855 --> 00:16:40,825
and do the same exact thing.

373
00:16:40,825 --> 00:16:44,035
Copy this, oops.

374
00:16:44,100 --> 00:16:46,330
Paste it in here.

375
00:16:46,330 --> 00:16:50,940
And the random number 1, oops, sorry.

376
00:16:50,935 --> 00:16:55,005
Now, random number 1 and random number two.

377
00:16:55,005 --> 00:16:59,335
And the level to go to is equal to random 2.

378
00:16:59,330 --> 00:17:02,900
And India, we are going to save that the level to go to

379
00:17:02,900 --> 00:17:07,250
is equal to the scene manager dot instance.

380
00:17:07,250 --> 00:17:09,290
Or we can say that level to go to

381
00:17:09,290 --> 00:17:10,880
as equal to level to go one.

382
00:17:10,880 --> 00:17:12,530
But you know what, I don't want to risk

383
00:17:12,530 --> 00:17:14,950
that does just keep things safe.

384
00:17:14,945 --> 00:17:17,515
But, oops, paste it in here,

385
00:17:17,510 --> 00:17:20,560
save that what is happening right now.

386
00:17:20,555 --> 00:17:22,795
So there is a problem because

387
00:17:22,790 --> 00:17:25,220
we cannot use the level exit to,

388
00:17:25,220 --> 00:17:28,750
we need to set the level to go to save that.

389
00:17:28,745 --> 00:17:30,295
So what's happening in here?

390
00:17:30,290 --> 00:17:31,760
We've set the level to go to,

391
00:17:31,760 --> 00:17:33,140
to be exactly as

392
00:17:33,140 --> 00:17:37,130
the scene manager or the index on the current scene.

393
00:17:37,130 --> 00:17:39,650
And in here we check what is

394
00:17:39,650 --> 00:17:41,840
the condition in here, as we've said,

395
00:17:41,840 --> 00:17:45,190
if we go back into our truth table of the off,

396
00:17:45,185 --> 00:17:46,855
let's keep it here and let's

397
00:17:46,850 --> 00:17:48,350
see how everything is looking.

398
00:17:48,350 --> 00:17:53,450
So we start off by checking as level to go to equal two,

399
00:17:53,450 --> 00:17:55,040
level to go one.

400
00:17:55,040 --> 00:17:57,790
And currently the level to go

401
00:17:57,785 --> 00:17:59,995
to or solid level to go one

402
00:17:59,990 --> 00:18:02,290
will be different than the current scene manager.

403
00:18:02,285 --> 00:18:05,395
So this condition is false, which is good.

404
00:18:05,390 --> 00:18:07,900
That means we will not enter into the while loop.

405
00:18:07,895 --> 00:18:10,915
But we then check level to go to,

406
00:18:10,910 --> 00:18:13,420
is it equal to the current build index?

407
00:18:13,415 --> 00:18:14,135
It is.

408
00:18:14,135 --> 00:18:17,845
Then we have a true condition which is right here,

409
00:18:17,840 --> 00:18:20,410
and a false condition which is right here.

410
00:18:20,405 --> 00:18:22,885
So if we look in the truth table,

411
00:18:22,880 --> 00:18:27,080
we have a true condition with a false condition,

412
00:18:27,079 --> 00:18:31,299
that means the whole set of conditions is true.

413
00:18:31,295 --> 00:18:34,085
That means we then go back into the while loop,

414
00:18:34,085 --> 00:18:36,085
and that's exactly what we want.

415
00:18:36,080 --> 00:18:39,830
If we have 11 of these true,

416
00:18:39,830 --> 00:18:41,750
we want to go back and create

417
00:18:41,750 --> 00:18:45,380
another random number and set the random number again.

418
00:18:45,380 --> 00:18:47,180
And we will keep doing that

419
00:18:47,180 --> 00:18:49,280
until this condition is false.

420
00:18:49,280 --> 00:18:51,250
And this condition is false,

421
00:18:51,245 --> 00:18:53,785
because only two conditions that are

422
00:18:53,780 --> 00:18:56,680
false make a total false.

423
00:18:56,675 --> 00:18:59,275
So back in here, if the level to go

424
00:18:59,270 --> 00:19:02,240
to different than the level to go one,

425
00:19:02,240 --> 00:19:04,640
and it's different than the current one.

426
00:19:04,640 --> 00:19:08,020
Only then when both of these are false,

427
00:19:08,015 --> 00:19:11,875
the entire condition is false and we continue on.

428
00:19:11,870 --> 00:19:13,700
So let's go back in here.

429
00:19:13,700 --> 00:19:15,470
We will print those and run

430
00:19:15,470 --> 00:19:17,330
the game and lets you know what,

431
00:19:17,330 --> 00:19:20,000
let's remove 11 manager who has remove one

432
00:19:20,000 --> 00:19:23,380
of the scary guys.

433
00:19:23,375 --> 00:19:25,975
And let's remove this one also and run

434
00:19:25,970 --> 00:19:29,410
the game because we want to demonstrate this pretty fast.

435
00:19:29,405 --> 00:19:33,625
So the enemy will appear in

436
00:19:33,620 --> 00:19:35,840
just a bit so that we will have

437
00:19:35,840 --> 00:19:38,270
only one skeleton to skeletons actually,

438
00:19:38,270 --> 00:19:41,490
once we killed them, we should see that.

439
00:19:42,820 --> 00:19:45,500
There we go. So we call them,

440
00:19:45,500 --> 00:19:47,060
go to the console,

441
00:19:47,060 --> 00:19:49,580
pause the video, pause the game.

442
00:19:49,580 --> 00:19:51,680
I mean, and you can see that we run them.

443
00:19:51,680 --> 00:19:53,320
Number 1 is 3,

444
00:19:53,315 --> 00:19:55,175
the random number 2 is 4.

445
00:19:55,175 --> 00:19:56,315
They are both different.

446
00:19:56,315 --> 00:19:59,465
We've picked levels, make sure to commit your changes,

447
00:19:59,464 --> 00:20:03,154
and I'll see you in the next one.

