1
00:00:00,240 --> 00:00:05,370
Hey, welcome back in the last lesson, we showed you how we can enter in a sequence and we can have

2
00:00:05,370 --> 00:00:10,230
the element moving and also you might have noticed that it stays with the last command.

3
00:00:10,470 --> 00:00:16,060
So we need to take care of that and we're going to add in and else here and if it's else.

4
00:00:16,060 --> 00:00:20,250
So that means that there are no more commands and that we've finished running the commands.

5
00:00:20,430 --> 00:00:29,100
So this is where we can update that inner HTML and set back that back to path and also have a return

6
00:00:29,100 --> 00:00:32,810
there so we don't execute anything else on this move or function.

7
00:00:33,240 --> 00:00:34,250
So let's try that.

8
00:00:34,260 --> 00:00:38,130
And now and we execute it, we end up with set path.

9
00:00:38,460 --> 00:00:40,590
So that's we have the ability to do that.

10
00:00:40,890 --> 00:00:45,350
And we can also add in the ability to get a random movement.

11
00:00:45,600 --> 00:00:48,400
So we'll make an application a little bit more interesting.

12
00:00:48,720 --> 00:00:53,880
So let's set up an array and we need an array with movement array.

13
00:00:54,720 --> 00:00:58,730
And then here is where we've got all the different directions that we want to move.

14
00:00:59,160 --> 00:01:05,570
So we've got right, we've got left up and of course, down.

15
00:01:05,910 --> 00:01:13,020
So now that we have an array with all the different possible movements, let's generate a random movement

16
00:01:13,020 --> 00:01:16,870
and add it into the function, into the add fun.

17
00:01:17,400 --> 00:01:18,300
So how do we do that?

18
00:01:18,510 --> 00:01:21,970
We need to select a random item from that array.

19
00:01:22,710 --> 00:01:26,520
So going into the console, we can use math random.

20
00:01:26,670 --> 00:01:34,320
And now that we do have that array, so that map movement array, you can see we've got all of the movements

21
00:01:34,320 --> 00:01:34,650
there.

22
00:01:34,950 --> 00:01:37,020
So if we take that movement array.

23
00:01:38,070 --> 00:01:44,260
And if we return back and index values of if want it to get the first one, we could do one and so on.

24
00:01:44,610 --> 00:01:52,440
So if we randomize this using a math flaw to bring the math value down to the floor so it gives us more

25
00:01:52,440 --> 00:02:02,130
control and then using math random, we need to multiply math random by the number of possible options

26
00:02:02,490 --> 00:02:06,240
and we can get that from the movement array using its length.

27
00:02:07,020 --> 00:02:07,380
So what?

28
00:02:07,380 --> 00:02:10,620
This will return back every time we enter it.

29
00:02:10,920 --> 00:02:13,670
It's going to enter in a random movement.

30
00:02:14,430 --> 00:02:18,270
So we see we've got all of them accounted for so we can apply this.

31
00:02:18,540 --> 00:02:20,930
And this is going to return back a random movement.

32
00:02:21,180 --> 00:02:27,700
And now all we need to do is associate it to a specific key so we can try that out.

33
00:02:27,750 --> 00:02:29,280
And how about we do the AKIE?

34
00:02:29,290 --> 00:02:31,070
So that's number 82.

35
00:02:31,080 --> 00:02:39,930
So I just pressed are just to see what it comes Barkhouse so we can check to see if key is equal to

36
00:02:40,200 --> 00:02:40,910
82.

37
00:02:41,790 --> 00:02:45,630
So if we do are we're going to get a random movement.

38
00:02:46,500 --> 00:02:49,070
So let's create a temporary variable for that.

39
00:02:49,080 --> 00:02:55,740
We can just call it temp and this is going to return back that random value coming out of that array.

40
00:02:56,550 --> 00:03:00,670
And then here we just simply add it to the array.

41
00:03:01,350 --> 00:03:02,220
So let's try that.

42
00:03:02,230 --> 00:03:07,200
So I'm just pressing R and you can see I'm getting random movements added in and then everything is

43
00:03:07,200 --> 00:03:07,800
still going to work.

44
00:03:07,800 --> 00:03:09,520
The same of sequence is going to work the same.

45
00:03:10,680 --> 00:03:12,840
So coming up next, so go ahead and add this into your project.

46
00:03:12,840 --> 00:03:20,100
So I add in and you can also have other keys, do different things and different movements as well.

47
00:03:20,430 --> 00:03:22,560
And you can also do combinations if you want.

48
00:03:23,190 --> 00:03:28,360
So coming up next, we're going to add in the ability to remove some of these commands.

49
00:03:28,380 --> 00:03:33,390
So if, for instance, you've got one of these commands, you don't want it within that array anymore.

50
00:03:33,540 --> 00:03:35,040
There's an option to remove it.

51
00:03:35,160 --> 00:03:39,840
So if you could click on it and remove it out, that's what we're going to add in an upcoming lesson.
