WEBVTT

00:07.260 --> 00:08.310
Welcome back.

00:08.310 --> 00:13.230
Now, in all RPGs, just about there's the ability to save your progress.

00:13.380 --> 00:18.720
And this is done in different ways depending on whether it's a single or a multiplayer game.

00:18.720 --> 00:21.030
And there are different ways to go about it.

00:21.060 --> 00:27.360
Now, when saving the game, we need to start thinking about what we need to save, what data is important.

00:27.780 --> 00:33.990
Well, we know that we have an attribute set with some attributes on it, and those attributes, at

00:33.990 --> 00:40.800
least the primary attributes are needed if we want all of the rest of our attributes to have the correct

00:40.800 --> 00:41.670
values.

00:42.270 --> 00:46.950
And as we level up, we spend attribute points on our primary attributes.

00:46.950 --> 00:53.310
So if we're looking for data that we need to save, at least our primary attributes would be part of

00:53.310 --> 00:54.210
that list.

00:54.860 --> 00:58.190
In addition to that, we have variables on our player state.

00:58.190 --> 01:03.890
So the player state contains some data that we're going to want to harvest and save whenever we save

01:03.890 --> 01:04.760
our project.

01:04.760 --> 01:12.590
And in this project, this just consists of four integers the level, the spell points, attribute points,

01:12.590 --> 01:14.210
and the XP.

01:14.860 --> 01:18.250
So those, of course, are data that we would like to save.

01:19.110 --> 01:19.530
Now.

01:19.530 --> 01:26.850
The ability system component itself has data of its own pertaining to our abilities, and luckily,

01:26.850 --> 01:32.340
we've set up our system in a really efficient manner where we can identify abilities by their ability

01:32.340 --> 01:33.180
tags.

01:33.240 --> 01:40.080
So gameplay tags are the only thing that we would need to save in order to keep track of our progress.

01:40.110 --> 01:46.680
Of course, they all have their own ability levels as well, and any other information that we may wish

01:46.680 --> 01:53.370
to save with our gameplay abilities could be lumped in to some kind of data structure, but either way,

01:53.370 --> 01:58.080
we do need to save information pertaining to our gameplay abilities.

01:58.910 --> 02:03.860
Now, these are all data that we would like to save and load for our character.

02:04.280 --> 02:09.530
But there could be additional information not stored in these variables that we would still want to

02:09.530 --> 02:10.100
save.

02:10.640 --> 02:19.820
This can include our location, perhaps the level or map that our character is in, and any other identifying

02:19.820 --> 02:23.750
value that we can use to retrieve our saved data.

02:23.750 --> 02:28.670
Some kind of a slot number or ID associated with the player.

02:29.030 --> 02:32.750
Any of that would be data that we would want to save as well.

02:32.750 --> 02:36.380
So we have a list of things that we're going to want to save.

02:36.380 --> 02:40.100
And now we need to think about how we're going to save it.

02:40.890 --> 02:44.190
Now there are two primary ways to save data.

02:44.220 --> 02:48.780
You could save the data to disk, your actual machine that you're playing on.

02:49.290 --> 02:55.830
So all of those values would now live on your machine and can be loaded from disk, or you could save

02:55.830 --> 03:02.550
to somewhere else, elsewhere in the cloud, or elsewhere on your machine, or onto another machine.

03:02.730 --> 03:06.150
This would be saving to a database of some kind.

03:06.630 --> 03:13.140
All of those values would be streamed across the network and saved somewhere else.

03:13.650 --> 03:16.530
And there are pros and cons to each way.

03:17.290 --> 03:24.070
If you save to an external database, then all of the data for the game is saved in a central location.

03:24.100 --> 03:25.540
This is for all users.

03:25.540 --> 03:32.440
So if this is a multiplayer game, it's the database that contains information pertaining to each user,

03:32.470 --> 03:34.510
not the user themselves.

03:35.080 --> 03:41.560
This is useful because if you save all of your player data to a database on one machine, you could

03:41.560 --> 03:47.920
log out and go to another machine and log in and still retrieve that saved information.

03:47.920 --> 03:52.000
Because it's not local to the machine, it's saved on a database.

03:52.890 --> 03:56.040
Another advantage is databases can be encrypted.

03:56.040 --> 03:58.260
So you could store sensitive information.

03:58.260 --> 04:03.720
And while encryption can be cracked, there's a level of security to it.

04:04.420 --> 04:07.840
Now dedicated servers use databases.

04:07.870 --> 04:14.680
This is typically the way to go for dedicated servers because the dedicated server does not have a player.

04:15.070 --> 04:21.520
The player is connecting to the server from elsewhere, and if the player is connecting to the server,

04:21.520 --> 04:28.090
then the server can connect to the database and have its information ready for the player.

04:28.540 --> 04:32.980
And doing it this way gives the server authority over the data.

04:32.980 --> 04:39.400
You see things that are determined by the client or sent from the client side up to the server.

04:39.400 --> 04:47.020
Run the risk of cheating as clients can be hacked, they can send fake values up to the server.

04:47.020 --> 04:52.510
And so for that reason, the server is typically seen as what should have authority.

04:52.510 --> 04:58.960
So saving to a database and having the server be in charge of saving and loading that data and sending

04:58.960 --> 05:01.960
it to the client is a secure way to do it.

05:02.590 --> 05:06.430
Now, the drawback to this method is it requires APIs.

05:06.430 --> 05:10.150
You need the ability to connect to a database.

05:10.150 --> 05:18.910
This requires expertise and knowledge about databases, how to write to and retrieve data from databases

05:18.910 --> 05:24.640
from within your game, and how to manipulate database data.

05:25.320 --> 05:25.740
Now.

05:25.740 --> 05:27.780
Saving to disk is simpler.

05:27.780 --> 05:30.240
It's typically easier to implement.

05:30.240 --> 05:31.170
It's faster.

05:31.170 --> 05:33.900
It doesn't require an external database.

05:34.290 --> 05:40.170
And for that reason, it's ideal for single player games as you don't really need to connect to a database

05:40.170 --> 05:40.890
elsewhere.

05:40.920 --> 05:47.880
Now, there are single player games that still do connect to dedicated servers and databases in order

05:47.880 --> 05:55.920
to keep track of important things in the game to facilitate in-game purchases, leaderboards, and such.

05:56.160 --> 05:59.580
But in the absence of that need, you could save to disk.

05:59.580 --> 06:05.550
And in reality, most multiplayer games use a combination where important information is stored on the

06:05.550 --> 06:09.240
database, but some information is stored to the disk.

06:09.630 --> 06:15.450
For example, when you have a login and a password and your app remembers the password that you've entered

06:15.450 --> 06:17.820
in that is saved to disk.

06:18.550 --> 06:22.030
Now a con to saving to disk is the data is local.

06:22.180 --> 06:27.640
So you could save your progress in the game on one machine and then go to another machine.

06:27.640 --> 06:34.420
Open up the game and that data is not there because you saved it locally to another machine's disk.

06:35.020 --> 06:36.400
That's a drawback.

06:37.020 --> 06:44.040
And some games again that are single player would still save some data to either a dedicated server

06:44.040 --> 06:46.920
or a database that the server can connect to.

06:47.790 --> 06:48.450
Now.

06:48.450 --> 06:56.340
Saving data externally to a database is outside the scope of this course, as that would require developing

06:56.340 --> 06:59.040
the ability to connect to the database.

06:59.070 --> 07:04.500
Teaching about how to retrieve and send to databases and from them.

07:04.500 --> 07:08.430
And that's really material for a course in itself.

07:08.430 --> 07:15.750
And I am planning on a course on dedicated servers that will talk about this in more detail.

07:16.110 --> 07:18.330
And we'll be creating a system for this.

07:18.330 --> 07:24.570
But in this course, which is primarily about the game play ability system, we're going to devise a

07:24.570 --> 07:26.370
system for saving to disk.

07:26.670 --> 07:33.420
But we'll do it in such a way that it could easily be swapped out for a system that saves to a database.

07:33.840 --> 07:39.780
Really, the only thing that matters is what data you're saving, how you're saving it, and where you're

07:39.780 --> 07:42.120
getting that data from when you load the game.

07:42.720 --> 07:49.530
The only thing that would change in a database based system is that you would add the capability to

07:49.530 --> 07:52.890
connect to the database or the dedicated server, or both.

07:53.430 --> 08:00.300
So in this final section in the course, we're going to implement a save game system where we can save

08:00.300 --> 08:07.710
our progress and load back in in the location where we were when we saved with the stats that we had

08:07.710 --> 08:08.850
when we saved.

08:09.150 --> 08:18.360
And this allows for a much more involved RPG, because if you retain your progress and load it back

08:18.360 --> 08:24.690
up every time you come back into the game, you haven't lost your progression and you can continue moving

08:24.690 --> 08:33.180
deeper into the game and venturing your way through deeper and darker dungeons and more complex levels

08:33.180 --> 08:34.140
and so on.

08:34.680 --> 08:42.150
So we're ready to start implementing a system for this, and we're going to need a way to load into

08:42.150 --> 08:42.930
the game.

08:42.930 --> 08:44.730
We'll need an opening screen.

08:44.730 --> 08:46.920
And we're going to start with that first.

08:46.920 --> 08:52.410
And then we'll work our way into figuring out how we can save our progress.

08:53.140 --> 08:54.100
I'll see you soon.
