﻿1
00:00:04,380 --> 00:00:05,520
‫Hello and welcome.

2
00:00:05,520 --> 00:00:11,310
‫In this lecture, we're going to be looking at how we can add dynamic text into our log messages using

3
00:00:11,310 --> 00:00:13,350
‫strings in C++.

4
00:00:13,350 --> 00:00:17,100
‫So let's dive in and learn about strings and C++.

5
00:00:17,340 --> 00:00:23,370
‫So we've seen how to print out some simple things from our UI log, but what if we wanted to print out

6
00:00:23,370 --> 00:00:29,550
‫some more text, something like the actor name, for example, or even something more complicated,

7
00:00:29,550 --> 00:00:33,330
‫such as a textual representation of a vector?

8
00:00:33,630 --> 00:00:40,350
‫Well, that does not typically have format specifiers because format specifiers have come to us from

9
00:00:40,350 --> 00:00:45,870
‫the age of C, which is a very basic programming language in comparison to C++.

10
00:00:45,870 --> 00:00:50,040
‫And so certain things just weren't thought up at the time.

11
00:00:50,040 --> 00:00:54,660
‫So things like vectors would not be included in the way that we format specify them.

12
00:00:54,660 --> 00:00:57,270
‫So we tend to use strings to do this.

13
00:00:57,270 --> 00:01:01,920
‫And as we've said in the past, strings are just text variables.

14
00:01:01,920 --> 00:01:06,900
‫They are variables that contain text so we can declare strings.

15
00:01:06,900 --> 00:01:11,280
‫In C++ we've used F vectors where we used vectors previously.

16
00:01:11,280 --> 00:01:17,190
‫Here we're going to use F string as the type for a string so we can have a string.

17
00:01:17,190 --> 00:01:21,240
‫And I'm just going to put in my string as the variable name for now.

18
00:01:21,240 --> 00:01:24,360
‫And how do we set a string value?

19
00:01:24,390 --> 00:01:26,940
‫Well, we've seen it a little bit around here already.

20
00:01:26,940 --> 00:01:31,560
‫These double quotes are what denote a string value in C++.

21
00:01:31,560 --> 00:01:36,060
‫So all of these expressions here, that one here where we've got the double quotes also over in the

22
00:01:36,060 --> 00:01:41,550
‫header file where we've got the double quotes for the category that is a string expression.

23
00:01:41,820 --> 00:01:49,800
‫So what we can do is set the my string variable from this and I'm going to say my string value just

24
00:01:49,800 --> 00:01:56,670
‫to give us an idea of that and put a semicolon at the end of the line and then how can we show this

25
00:01:56,670 --> 00:01:58,680
‫in a log statement?

26
00:01:58,680 --> 00:02:06,570
‫So I'm just going to remove the move distance from here as an argument to the log, and I'm going to

27
00:02:06,600 --> 00:02:14,820
‫change the text in the log message to say, here's my string colon.

28
00:02:14,820 --> 00:02:21,840
‫And then instead of the F specify, we use percent SSE this time to denote the string that we want to

29
00:02:21,840 --> 00:02:22,680
‫print out.

30
00:02:22,680 --> 00:02:28,830
‫And then the argument we pass into the E log function again between these two brackets is going to be

31
00:02:28,830 --> 00:02:30,300
‫my string.

32
00:02:30,990 --> 00:02:34,890
‫Now unfortunately that would be great if that just worked by itself.

33
00:02:34,890 --> 00:02:42,030
‫But unfortunately there's a little bit of a complication here in Unreal that they won't accept a straightforward

34
00:02:42,030 --> 00:02:44,490
‫string as an argument to the YUI log.

35
00:02:44,490 --> 00:02:50,340
‫It needs a little bit of a converting operator here, and the way we do this is by putting an asterisk

36
00:02:50,340 --> 00:02:55,890
‫in front of the my string and it just converts it from an F string into the format that it's looking

37
00:02:55,890 --> 00:02:58,320
‫for internally within the U log.

38
00:02:58,320 --> 00:03:02,220
‫We don't have to go into too much detail as to why it's doing this.

39
00:03:02,580 --> 00:03:06,390
‫It's it's beyond the level that we need to know at this point in time.

40
00:03:06,390 --> 00:03:13,260
‫I think it's just important to learn it as it is that when we do a percent se, we always need a star

41
00:03:13,260 --> 00:03:15,690
‫in front of our f strings.

42
00:03:15,690 --> 00:03:19,830
‫So let's see if that's worked by going over into Unreal and hitting the compile button.

43
00:03:19,830 --> 00:03:25,560
‫And then we're going to close down the live coding, hit play, open up the output log and here you

44
00:03:25,560 --> 00:03:28,050
‫go, here's my string, my string value.

45
00:03:28,050 --> 00:03:31,890
‫So it's printing out the value in the my string.

46
00:03:31,890 --> 00:03:37,230
‫But obviously this piece of code that I've just written is not particularly useful because well, I

47
00:03:37,230 --> 00:03:38,820
‫could have just written this string into here.

48
00:03:38,820 --> 00:03:41,430
‫Why bother with this whole substitution business?

49
00:03:41,580 --> 00:03:47,850
‫Well, where this gets more interesting is where we put a dynamic value into this variable instead.

50
00:03:48,210 --> 00:03:51,630
‫So we could do get name and call that.

51
00:03:51,630 --> 00:03:57,630
‫That is a function here available in the moving platform actor that gets the name of the actor that

52
00:03:57,630 --> 00:04:00,990
‫we see in the level out liner, we can put it into the variable.

53
00:04:00,990 --> 00:04:07,710
‫I'm going to call that variable name instead of my string and change its name down here in the US log

54
00:04:07,710 --> 00:04:08,490
‫as well.

55
00:04:08,490 --> 00:04:17,940
‫So then we can change the text of the log message to say begin play colon and then it's going to be

56
00:04:17,940 --> 00:04:19,410
‫the name of the actor.

57
00:04:19,410 --> 00:04:26,220
‫So let's go back into unreal, stop play, hit, compile, go ahead and hit play and open up the output

58
00:04:26,220 --> 00:04:31,890
‫log and you can see we get the messages begin play moving platform one begin play moving.

59
00:04:31,890 --> 00:04:33,180
‫Platform three pushing.

60
00:04:33,180 --> 00:04:35,460
‫Kub three pushing, keep five, pushing, keep seven.

61
00:04:35,460 --> 00:04:39,150
‫So we've got big in play and all the names of the different actors.

62
00:04:39,150 --> 00:04:46,260
‫Now this can be very useful because later on down the line where we're printing out our overshoot distance,

63
00:04:46,260 --> 00:04:54,570
‫it's not always clear who is overshooting in this case because they're all getting messed up together.

64
00:04:54,570 --> 00:05:00,990
‫So being able to print out the name of the actor that is producing the log message can be really helpful

65
00:05:00,990 --> 00:05:03,780
‫in pinpointing where a problem is.

66
00:05:03,840 --> 00:05:04,410
‫Happening.

67
00:05:04,410 --> 00:05:11,130
‫So I'd like to challenge you to log the name with that overshoot log so that we are going to see who

68
00:05:11,130 --> 00:05:13,140
‫has overshot and by how much.

69
00:05:13,350 --> 00:05:20,070
‫So you're going to add a variable for the name of the actor to tick like we did in Begin Play.

70
00:05:20,430 --> 00:05:27,870
‫You're going to get name into it and you're going to add a percent as specified somewhere anywhere you

71
00:05:27,870 --> 00:05:35,040
‫like into your log message where we're printing that overshoot and you're going to add an argument for

72
00:05:35,070 --> 00:05:35,730
‫that name.

73
00:05:35,730 --> 00:05:42,720
‫We still want the overshoot variable in the list of arguments, but after all, before that one, you're

74
00:05:42,720 --> 00:05:46,380
‫going to have to put the argument for the name as well.

75
00:05:46,620 --> 00:05:52,200
‫And it's important to hear that the order of the argument matches the order of the specifiers in your

76
00:05:52,200 --> 00:05:52,620
‫message.

77
00:05:52,620 --> 00:05:57,180
‫So if you put percents before percent f, then that's the order.

78
00:05:57,180 --> 00:06:02,610
‫The name should go before the overshoot or you should do it the other way round if you've done the other.

79
00:06:02,880 --> 00:06:09,150
‫And don't forget to add the star before your variable name to convert the string into something that

80
00:06:09,150 --> 00:06:11,460
‫the log you e log can use.

81
00:06:11,460 --> 00:06:13,140
‫Pause the video and have a go.

82
00:06:16,070 --> 00:06:16,490
‫Okay.

83
00:06:16,490 --> 00:06:17,450
‫Welcome back.

84
00:06:17,480 --> 00:06:25,610
‫So we're going to start off by getting a variable and this isn't strictly necessary, but we are going

85
00:06:25,610 --> 00:06:30,230
‫to use the variable just for simplicity's sake and keeping that line a bit shorter.

86
00:06:30,230 --> 00:06:36,560
‫So we're going to have an F string called name using uppercase letters, usually to start our variable

87
00:06:36,560 --> 00:06:36,950
‫names.

88
00:06:36,950 --> 00:06:44,600
‫We're going to do a get name in to that variable and then we're going to use it as an argument.

89
00:06:44,600 --> 00:06:48,080
‫But where am I going to put my format, specify it in the log message?

90
00:06:48,080 --> 00:06:53,870
‫Well, I'm going to put it as the first thing in my log message to kind of make it clear that this is

91
00:06:53,870 --> 00:06:55,850
‫a log message coming from this thing.

92
00:06:55,850 --> 00:07:02,180
‫So I'm going to put percent s first, and that means that my argument needs to go before the overshoot

93
00:07:02,180 --> 00:07:02,750
‫argument.

94
00:07:02,750 --> 00:07:08,660
‫So we're going to get their name, put it in here, and we need to put an asterisk in front of the name

95
00:07:08,660 --> 00:07:11,420
‫in order to convert it appropriately.

96
00:07:11,420 --> 00:07:13,340
‫Now, let's go back into the editor.

97
00:07:13,340 --> 00:07:19,610
‫Stop playing hit recompile, close the terminal, hit play and open the output log.

98
00:07:20,060 --> 00:07:24,530
‫And you can see that we're starting to get our tick messages coming through.

99
00:07:24,560 --> 00:07:28,010
‫Got push and cube overshot by one push and q11.

100
00:07:28,010 --> 00:07:34,190
‫So you can see here you can make a conclusion that we couldn't make before, which is that the faster

101
00:07:34,190 --> 00:07:40,100
‫moving platforms, the pushing cubes are the ones overshooting by more, whereas the moving platforms

102
00:07:40,100 --> 00:07:44,390
‫seem to be overshooting by less, which is what I would expect.

103
00:07:44,390 --> 00:07:47,840
‫But it's good to see it confirmed here in the logs.

104
00:07:47,870 --> 00:07:48,440
‫Great stuff.

105
00:07:48,440 --> 00:07:51,710
‫So that's it for our little logging diversion.

106
00:07:51,710 --> 00:07:56,330
‫Hopefully you found this interesting and I will see you in the next lecture.

