﻿1
00:00:04,020 --> 00:00:04,980
‫Hello and welcome.

2
00:00:04,980 --> 00:00:11,100
‫In this lecture, we're going to be making it so that when you use up all of your projectiles, your

3
00:00:11,100 --> 00:00:14,010
‫game will automatically restart the current level.

4
00:00:14,010 --> 00:00:18,810
‫After a pause of 5 seconds, let's dive in and see how this is done.

5
00:00:19,080 --> 00:00:24,660
‫So one element of this game that's not particularly fun right now is that when you run out of ammo,

6
00:00:24,660 --> 00:00:25,650
‫it's a dead end.

7
00:00:25,650 --> 00:00:26,910
‫You can't try again.

8
00:00:26,910 --> 00:00:27,930
‫You can't do anything else.

9
00:00:27,930 --> 00:00:29,820
‫You can't move on to another level.

10
00:00:30,150 --> 00:00:38,160
‫Now, the way you can fix this is by allowing us to reload the current level.

11
00:00:38,880 --> 00:00:42,750
‫The way you can do that is using a special node in blueprint.

12
00:00:42,750 --> 00:00:47,430
‫So if you right click in the event graph, you open up your level blueprint and right click in the event

13
00:00:47,430 --> 00:00:47,850
‫graph.

14
00:00:48,180 --> 00:00:50,580
‫We can search for open level.

15
00:00:50,580 --> 00:00:51,720
‫And there's two options here.

16
00:00:51,720 --> 00:00:55,650
‫There's an open level by name and an open level by object reference.

17
00:00:55,800 --> 00:00:59,520
‫We can use the open level by name.

18
00:00:59,520 --> 00:01:06,510
‫So here you got a node that obviously has side effects because it's going to reload the level and it

19
00:01:06,510 --> 00:01:09,150
‫has an input, which is the level name here.

20
00:01:09,600 --> 00:01:12,000
‫Now how do we get hold of the current level name?

21
00:01:12,000 --> 00:01:19,050
‫We could just type it in, but what if we accidentally renamed this level at some point in the future?

22
00:01:19,350 --> 00:01:28,710
‫Well, what we can do is also right click and do a get current level name, which gets us another node

23
00:01:28,710 --> 00:01:30,930
‫that returns the current level name.

24
00:01:30,930 --> 00:01:33,990
‫Interestingly enough, this one isn't a pure function.

25
00:01:33,990 --> 00:01:35,070
‫I have no idea why.

26
00:01:35,130 --> 00:01:36,840
‫Because it looks like it should be.

27
00:01:36,930 --> 00:01:42,150
‫And what we can do is even though these two types are different, one of them returns a string and the

28
00:01:42,150 --> 00:01:44,400
‫other one requires something of type name.

29
00:01:44,400 --> 00:01:51,120
‫It's actually possible to very easily convert between strings and names so we can drag from the return

30
00:01:51,120 --> 00:01:56,430
‫value to the input value, and a conversion node will automatically be created for us.

31
00:01:56,430 --> 00:02:01,350
‫We also need to hook up the execution pin between these two, so we're going to get the current level

32
00:02:01,350 --> 00:02:04,380
‫name convert and then open the level.

33
00:02:04,800 --> 00:02:06,870
‫Now when is it that we want to do this?

34
00:02:06,870 --> 00:02:12,900
‫Currently everything is happening either on a key event or begin play, but there is another option.

35
00:02:12,900 --> 00:02:20,640
‫What we can do is we can have a special node in the root event graph, so not within functions but within

36
00:02:20,640 --> 00:02:23,010
‫the root event graph called a delay node.

37
00:02:23,010 --> 00:02:29,220
‫So what we're going to do is after the out of ammo is pressed, we're going to pull off of the execution

38
00:02:29,220 --> 00:02:31,560
‫pin here and search for delay.

39
00:02:32,220 --> 00:02:37,080
‫And then you can see it brings in a special kind of node with a clock on it.

40
00:02:37,080 --> 00:02:45,480
‫And this means that the output happens not instantly after the function has finished, but it happens

41
00:02:45,480 --> 00:02:47,040
‫after a certain amount of time.

42
00:02:47,040 --> 00:02:53,490
‫So you can see we can input the duration here, and that duration could be 5 seconds, for example.

43
00:02:53,490 --> 00:03:04,020
‫So in my print string, I'm going to update it to say out of ammo restarting in 5 seconds and then dot,

44
00:03:04,020 --> 00:03:04,710
‫dot, dot.

45
00:03:05,100 --> 00:03:15,300
‫And then we can plug in the code that restarts the level into the output, the completed node of the

46
00:03:15,300 --> 00:03:16,650
‫delay node.

47
00:03:16,740 --> 00:03:24,390
‫So if we go ahead and play now, what we're going to see is that I can run out of ammo, finish all

48
00:03:24,390 --> 00:03:31,530
‫of my ammo, I run out and it says I'm restarting in 5 seconds and after 5 seconds has elapsed, boom,

49
00:03:31,530 --> 00:03:33,540
‫the level has just restarted.

50
00:03:33,540 --> 00:03:40,950
‫So small challenge for this lecture is to extract a function from those nodes that we've just created,

51
00:03:40,950 --> 00:03:43,830
‫the get current level, name and open level.

52
00:03:43,830 --> 00:03:48,810
‫And my challenge to you is to just think of a good name for this function.

53
00:03:48,810 --> 00:03:50,430
‫Pause the video and have a go.

54
00:03:53,740 --> 00:03:54,050
‫Okay.

55
00:03:54,060 --> 00:03:54,660
‫Welcome back.

56
00:03:54,660 --> 00:03:59,370
‫Well, I'm going to call it restart level because that's what I think it's doing.

57
00:03:59,370 --> 00:04:07,950
‫So I'm going to right click collapse to function and call it restart level and it's fine with the current

58
00:04:07,950 --> 00:04:08,460
‫inputs.

59
00:04:08,460 --> 00:04:12,690
‫It doesn't need to be pure because it has the side effect of restarting the level.

60
00:04:12,690 --> 00:04:14,970
‫So we wouldn't want it to be pure anyway.

61
00:04:14,970 --> 00:04:15,690
‫So that's it.

62
00:04:15,690 --> 00:04:22,170
‫I'm just going to reorganize my nodes ever so slightly and delete my test node and delete my test function

63
00:04:22,170 --> 00:04:25,170
‫by right clicking on it in the my blueprints and hitting delete.

64
00:04:25,470 --> 00:04:33,240
‫And we've got ourselves a condensed little blueprint graph that actually describes exactly what our

65
00:04:33,240 --> 00:04:36,420
‫game can do just at a very high level.

66
00:04:36,420 --> 00:04:37,830
‫So I'm pleased with the results of that.

67
00:04:37,830 --> 00:04:41,640
‫Feels like we've got a good game loop and I'll see you in the next lecture.

