WEBVTT

00:00.850 --> 00:02.710
Welcome to your next quest.

00:02.980 --> 00:07.030
Now we know that we need a data asset for our level up info.

00:07.060 --> 00:14.440
Now your quest is to create one and add an array of structs to your level up info so that we can have

00:14.440 --> 00:17.620
the amount of information we need for each level up.

00:17.620 --> 00:22.870
That includes level up requirement, attribute point, reward, and spell point reward.

00:22.960 --> 00:29.500
Now, as a bonus, you can make a function to find the level for a given amount of exp.

00:29.830 --> 00:37.060
So you pass in the amount of exp and the function will find what level you should be at for that amount

00:37.060 --> 00:37.570
of exp.

00:37.780 --> 00:41.920
Remember exp is cumulative right over the course of the whole game.

00:41.920 --> 00:48.700
So if you're up to the extra challenge, figure out how to find that level for a given amount of exp.

00:49.000 --> 00:52.570
So pause the video and conquer this quest now.

00:55.680 --> 00:57.900
Okay, so we need a data asset.

00:57.900 --> 01:04.710
That means we're going to go into C plus plus classes or a public and I'll put this in ability system

01:04.710 --> 01:07.490
data with our other data assets here.

01:07.500 --> 01:15.480
So new C plus plus class, we're going to create a data asset and click next.

01:15.480 --> 01:19.440
And this can be called level up info.

01:19.800 --> 01:24.510
So we'll create the class, we'll close the editor and we'll define it here.

01:24.510 --> 01:28.230
So let's go to public ability system data.

01:28.320 --> 01:32.190
We'll open level up info and close all other tabs.

01:32.220 --> 01:40.170
I'll go ahead and get both CP and H files open and here in the header file, the first thing we need

01:40.170 --> 01:42.060
to do is create a struct.

01:42.060 --> 01:42.420
Right?

01:42.420 --> 01:46.080
We need a struct with our level up info for each level.

01:46.080 --> 01:49.260
So we'll go ahead and create that struct here.

01:49.290 --> 01:52.740
Called for a level up info.

01:53.790 --> 01:58.330
Now this will be a use struct with blueprint type.

01:58.330 --> 02:04.000
It gets a generated body and we're going to have basically three values here.

02:04.000 --> 02:11.380
We're going to have a level up requirement and for level up requirements, this is a number an amount

02:11.380 --> 02:15.040
of exp required in order to level up.

02:15.040 --> 02:20.470
Now for Exp, I'd like to use discrete numbers integers rather than floats.

02:20.470 --> 02:22.660
So it's kind of cut and dry.

02:22.660 --> 02:25.360
Whether or not you have enough exp to level up.

02:25.360 --> 02:32.410
You have a number of points and if you don't have enough to level up then you don't level up.

02:32.410 --> 02:35.950
So for that reason, these are going to be integer numbers.

02:35.950 --> 02:44.590
We're going to have an INT 32 and this will be a level up requirement and we'll give it a default value

02:44.590 --> 02:45.340
of zero.

02:45.340 --> 02:50.110
But this will be designed to be set from our data asset for each level.

02:50.110 --> 02:56.680
So it's going to be edit defaults only and I don't see an immediate need to expose it to the event graph.

02:56.770 --> 03:02.140
Now, in addition to the level up requirement, I'd like to know how many attribute points I should

03:02.140 --> 03:06.160
be rewarded for leveling up to this level.

03:06.160 --> 03:13.720
So I'm going to make an INT 32 called Attribute Point Award, and by default it'll be one.

03:13.720 --> 03:20.380
And this will make it easier if most of the time we just want to gain one attribute point when leveling

03:20.380 --> 03:23.530
up, then for most of these we won't have to change it.

03:23.530 --> 03:29.290
And then every once in a while perhaps we can get to attribute points for leveling up and so on.

03:29.290 --> 03:36.340
And we haven't created any spell points, but we're going to so when we level up, we'll be able to

03:36.340 --> 03:37.960
spend points on spells as well.

03:37.960 --> 03:43.150
So I'm going to have another int 32 called spell point reward or award.

03:43.360 --> 03:45.640
Either one is fine award.

03:45.640 --> 03:52.060
Sounds like you're going to be awarded this many attribute points, but we could call it spell point

03:52.060 --> 03:53.080
reward.

03:53.080 --> 03:55.150
And then it's like, this is your reward.

03:56.620 --> 04:02.470
I don't think it's terribly important which one we use, so I'm going to call it spell point award for

04:02.470 --> 04:06.430
the amount we award someone when they level up.

04:06.490 --> 04:11.140
So now that we have this aura level up info, we need an array of these.

04:11.140 --> 04:21.850
So we're going to make a public section and make a T array of F or a level up infos called level up

04:22.240 --> 04:23.500
information.

04:24.280 --> 04:27.130
Now this will be filled in in the blueprint.

04:27.250 --> 04:33.490
So edit defaults only it gets and we have our data asset.

04:33.550 --> 04:42.060
Now for a bonus, we have the task of creating a function to find the level for a given amount of experience.

04:42.070 --> 04:50.050
So what we can do is make an int 32 returning function called find level for exp where we take an int

04:50.050 --> 04:58.280
32 called exp and return what level we should be at for that amount of experience points.

04:58.610 --> 05:00.560
So how are we going to do this?

05:00.560 --> 05:09.020
Well, we have level up information which is a t array and the index for our t array is going to be

05:09.020 --> 05:09.980
the level, right?

05:09.980 --> 05:16.700
So level up information index dot one will contain the struct for level one.

05:16.850 --> 05:23.330
Now because we're indexing by level and not by, say, the level up info in a map.

05:23.330 --> 05:30.350
For example, we can't just do a random access lookup, we're going to have to go through the array

05:30.350 --> 05:32.660
until we find the correct level.

05:32.660 --> 05:41.750
So a simple algorithm would be to create some kind of a loop, like a while loop and while can search

05:41.750 --> 05:44.390
through the array until it finds something.

05:44.390 --> 05:52.250
So I can make a boolean called Be searching and set it equal to true and execute the while loop while

05:52.280 --> 05:54.350
be searching is true.

05:54.350 --> 05:55.760
So while be searching.

05:55.760 --> 06:01.400
And then at some point we can set it to false as soon as we find the correct level up requirement.

06:01.430 --> 06:04.340
Now we need to know what level to return.

06:04.340 --> 06:13.790
So I'm going to create a local int 32 called level and we'll start it off at level one and in our loop,

06:13.790 --> 06:18.920
once we're done with our loop, this should be set to the correct level and we'll return that at the

06:18.920 --> 06:19.100
end.

06:19.100 --> 06:21.050
So we'll return level at the end.

06:21.050 --> 06:23.180
So the question is what does our loop do?

06:23.210 --> 06:28.640
Well, the first thing we should do is check our level up information and make sure it has enough elements

06:28.640 --> 06:29.270
in it.

06:29.270 --> 06:36.950
In other words, we should say if level up information dot num, like how many elements are in the array?

06:36.980 --> 06:42.800
If it's less than or equal to level, then we should return Y because well, let's say level up, information

06:42.800 --> 06:43.430
is empty.

06:43.460 --> 06:45.170
It has zero elements in it.

06:45.170 --> 06:50.720
While level will be one and level up information num will be zero.

06:50.720 --> 06:54.770
So in this case we should just return and we'll return level.

06:54.770 --> 06:56.840
We'll just say one in that case.

06:56.930 --> 07:00.440
Now level up information should at least have one element in it.

07:00.440 --> 07:07.610
And if it does have exactly one, well then we should also return level because that's the only level

07:07.610 --> 07:09.140
that we have stored in there.

07:09.170 --> 07:15.260
Now, if it has two, for example, then level up information dot num will be two.

07:15.260 --> 07:19.640
And that's really just for elements zero and one.

07:19.640 --> 07:26.510
And the convention that I'd like to use is that first element in level up information will correspond

07:26.510 --> 07:27.320
to no level.

07:27.320 --> 07:29.150
It'll be just a placeholder.

07:29.150 --> 07:32.150
So that element one can be for level one.

07:32.150 --> 07:38.570
So in the case that level up information dot num is two and level is one.

07:38.570 --> 07:42.050
Well in that case we want to return one, right?

07:42.050 --> 07:47.950
So really we could have level up information num minus one here.

07:47.960 --> 07:49.400
Now let's think about this.

07:49.430 --> 07:55.460
If level up information has three elements, if level up, information has three elements and level

07:55.460 --> 08:00.680
is one, then level up information dot num minus one is two.

08:00.830 --> 08:02.840
That is not less than or equal to one.

08:02.840 --> 08:04.340
So we would continue.

08:04.340 --> 08:17.750
So what we can say here in a comment is level up information at one equals level one information, right?

08:17.750 --> 08:26.540
And level up information at two equals level two information.

08:27.870 --> 08:32.580
So this means that level up information at zero is meaningless.

08:32.610 --> 08:34.020
It's just a placeholder.

08:34.230 --> 08:41.580
Okay, So if we reach past this return, then that means we're going to need to search and see what

08:41.610 --> 08:43.200
level we should return.

08:43.200 --> 08:45.090
And that's going to depend on XP.

08:45.540 --> 08:47.530
So what we can do is make a check.

08:47.550 --> 08:55.380
We can check if XP is greater than or equal to level up information at the level.

08:55.980 --> 09:00.510
Now level up information at this level returns a struct.

09:00.510 --> 09:05.340
So if we use the dot operator, then we can access that level up requirement.

09:05.370 --> 09:11.730
That's going to tell us how much is required to level up at this particular level.

09:11.760 --> 09:13.950
So we start off with level equals one.

09:13.950 --> 09:18.240
We're assuming we have enough elements in level up information to search it.

09:18.270 --> 09:22.320
Now let's say that XP is say between 0 and 300.

09:22.320 --> 09:24.900
In other words, level should be one, right?

09:24.930 --> 09:29.650
Well, level starts at one here locally and XP.

09:29.680 --> 09:31.300
Let's just say it's 100.

09:31.330 --> 09:33.670
That means we should be level one, right?

09:33.790 --> 09:40.240
Well, if we look up the array indexing at level one and we get that level up requirement, that should

09:40.240 --> 09:48.370
be 300 for level one, which means that XP is not greater than or equal to level up requirement.

09:48.460 --> 09:54.850
So in that case, we can set be searching to false and exit the while loop and return level so we can

09:54.850 --> 09:59.530
have an else case here that says be searching equals false.

09:59.860 --> 10:03.510
Now what do we do if we make it to the inside of the If statement?

10:03.520 --> 10:08.260
In other words, XP is greater than the level up requirement of our current level.

10:08.470 --> 10:11.350
Let's say the amount of XP is 400.

10:11.380 --> 10:15.040
That's greater than the level one requirement, right?

10:15.040 --> 10:22.020
So what we can do is add one to level, we can say plus plus level, and then our loop will start over.

10:22.030 --> 10:27.970
So if level up information has enough elements in it, level has just gone up to two, right?

10:28.000 --> 10:32.650
That means level up information should at least have three elements in it.

10:32.680 --> 10:36.490
If it does, three minus one would be two.

10:36.520 --> 10:41.200
That would be less than or equal to level, which would be two now.

10:41.200 --> 10:42.680
So we'd return level.

10:42.700 --> 10:44.140
See how that works.

10:44.230 --> 10:51.040
But if level up information has way more than three elements, let's say it has, say, ten, well then

10:51.040 --> 10:52.690
we won't get past this.

10:52.690 --> 10:55.720
So what we'll do is we'll check our condition again.

10:55.930 --> 11:02.920
XP was we said 400 and we can check now against level up information at level two.

11:02.950 --> 11:08.050
Now let's say at level two, the level up requirement is 900.

11:08.080 --> 11:14.920
Well, in that case, we would not reach the inside of this if statement because our XP was 400.

11:14.950 --> 11:18.190
So we would get to the else be searching would be false.

11:18.220 --> 11:20.500
We would exit early and return level.

11:20.650 --> 11:26.650
So this gives us a function to search through the array and return the correct level.

11:26.650 --> 11:28.330
And yeah, it's a while loop.

11:28.330 --> 11:34.270
So the maximum number of iterations would be the length of our array.

11:34.270 --> 11:39.640
And this also allows us to see what level we should be for any XP amount.

11:39.640 --> 11:46.630
So if we're at level one and we gain 1000 experience points, if that's enough for a double level up,

11:46.630 --> 11:50.020
we'll know because we'll know what we were at before.

11:50.020 --> 11:51.700
We'll know what we should be at.

11:51.700 --> 11:52.330
Now.

11:52.330 --> 11:58.750
If that's two levels or three levels up, then we know we got a double or a triple level up and so on.

11:58.960 --> 12:03.820
So now that we have level up info, all we need to do is make the blueprint.

12:03.820 --> 12:08.500
So let's compile and launch the editor and make our data asset blueprint.

12:09.640 --> 12:14.230
Okay, so let's make our blueprint based on level up info.

12:14.260 --> 12:22.690
I can go into blueprints ability system data, right click, go to miscellaneous and data asset and

12:22.690 --> 12:24.610
we can search for level up info.

12:25.360 --> 12:28.540
And create a data asset based on that.

12:28.540 --> 12:32.200
We'll call it a level up info.

12:33.670 --> 12:34.690
Let's open that up.

12:34.690 --> 12:36.310
And we have an empty array.

12:36.340 --> 12:43.120
Now if we click plus we know that the zeroth element is just a placeholder, so we're not going to set

12:43.120 --> 12:44.270
anything here.

12:44.290 --> 12:49.860
We want to click plus again and we'll have our level up requirement for level one.

12:49.870 --> 12:53.500
So again, we could have used a curve table for this.

12:53.500 --> 12:59.200
I'm not I'm going to use this way because I like to set things manually just in case.

12:59.200 --> 13:04.900
We want different values and I don't want to have to create curve tables for multiple things.

13:04.900 --> 13:06.940
All I have to do is add to this struct.

13:06.940 --> 13:11.090
If I want something else to put in this data asset per level.

13:11.110 --> 13:15.790
Now for level one, I want my level up requirement to be 300.

13:15.830 --> 13:22.120
We'll likely create some kind of a placeholder level up info for testing so that we can level up much

13:22.150 --> 13:30.340
faster but 300 XP to reach level two sounds good to me and I'm going to click plus a whole bunch more

13:30.340 --> 13:36.080
times so that I can have level up requirements for levels one through ten.

13:36.110 --> 13:39.080
Now, how do you choose these values?

13:39.080 --> 13:42.230
Well, one way is to take a look at other games.

13:42.230 --> 13:45.440
Another way is to kind of ballpark estimate.

13:45.470 --> 13:50.570
Another is to just fill this in as you go, as you're playtesting.

13:50.570 --> 13:54.320
Now, there are lots of other popular role playing games.

13:54.320 --> 13:59.060
Some are video games, some are tabletop RPGs.

13:59.060 --> 14:03.590
And there's one pretty good one you could use as a reference.

14:03.620 --> 14:09.350
It rhymes with Dungeons and Dragons, and I'm going to use numbers that are similar to that.

14:09.350 --> 14:13.310
So my level up requirement for level two is going to be 900.

14:13.580 --> 14:17.300
For level three, it's going to be 2700.

14:17.840 --> 14:21.920
For level four, it's going to be 6400.

14:22.460 --> 14:29.450
For level five, it's going to be 14,000 514,500.

14:29.450 --> 14:34.910
And at level five, I'd like to gain two attribute points and to spell points.

14:34.910 --> 14:40.820
So now we can see that we don't have to just get one point every time we level up, we can change this.

14:40.820 --> 14:43.010
So level five is a special level up.

14:43.010 --> 14:46.910
We get two points right so we can do something special like that.

14:47.000 --> 14:55.820
For level six, I'm going to have a level up requirement of 20,000, and for seven it's going to be

14:55.820 --> 14:58.340
35,000.

14:58.340 --> 15:00.800
That is for level eight.

15:00.800 --> 15:06.830
I'm going to go ahead and go up to 50,000 for level nine.

15:06.860 --> 15:09.350
It's going to be 65,000.

15:10.220 --> 15:13.430
And for level ten, it's going to be 85,000.

15:14.180 --> 15:21.320
So now you can see that a mathematical formula might be hard to manage as the number of levels increases.

15:21.320 --> 15:24.200
But manually setting these makes it a little easier.

15:24.200 --> 15:29.840
And this is kind of cool because you're seeing that as the game progresses, as your character gets

15:29.840 --> 15:30.850
higher and level.

15:30.860 --> 15:33.110
We're dealing with higher numbers here.

15:33.110 --> 15:40.190
At first you needed a measly 300 experience to level up to level two, but when you're level nine,

15:40.220 --> 15:42.350
you need 65,000.

15:42.350 --> 15:47.060
But then again, you'll be slaying monsters that give you a higher number here.

15:47.060 --> 15:52.340
So this is one of the ways that RPGs can make you feel a sense of accomplishment.

15:52.370 --> 15:58.550
You're capable of gaining much higher values for your XP, which is quite nice.

15:58.760 --> 16:04.550
Okay, so now that we have level up info that takes care of that step.

16:05.560 --> 16:09.190
And we'll continue in the next video with the next task.

16:09.220 --> 16:10.270
I'll see you soon.
