 Hello guys, welcome back to another video for Idle Games Tourism series, welcome to episode 5. So this one's gonna be really the basic basics of saving and loading. I have developed recently a brand new really advanced save and load system that I'll probably won't get in this tutorial, but I'll tutorial sorry, but I won't but I will share eventually once it's actually fully functional. Anyways, so we are going to, we're gonna get started. So basically we want to save all these numbers and load it. And we will fix this right here. We don't need these over here once the system is done. So saving and loading requires, actually it doesn't really require, but I recommend creating two methods for this because it makes your code a lot easier. So we're going to create public void load. No, not that kind of load, load load. And then we're going to make public void save. All right, so now we got load and save. So nothing happens, but on load, you just want to start, you know, we just want to call the load function. And for save, we can make it save every five seconds or every frame. It's recommended to have it or make it update every certain interval. But for this tutorial, we're just going to do every frame. So 144 times per second, not very good optimization. I usually do every five seconds, but it's whatever you guys want to do depends on how good your game is or how big your game is. So anyways, loading, we're going to take all these variables that we want to load with. We want, we don't want clicks value. Actually, yeah, we did, we did. Okay, we already got that. We're going to add coins, temporary. Let's see. We need levels. Yes, big time. We need levels. Okay, and one more. So we don't need the coins per second since it's always changing because of other variables. And these are the only ones that we want to save because it relies on them. So, okay. So this is all of our variables right here. Oops. So we're going to start with, we're going to start with doubles. I mean, all the levels are going to go on the bottom, spaced out. These are all it's. And we don't have any floats. So we don't have to worry about it. But there's one thing we have to do. If we're going to be using player press, we need to convert to string when we save and load. Why? Because player plus doesn't bleed out. I'm talking really fast. Sorry. But simply because player press do not save or get doubles sucks. It only floats instant. Um, it's string. Yeah. String floats it is. All right. So we're going to start with coins, click value. We actually, we need coins too, obviously. So we're going to start with coins. So to load, we want to set that value as um, we want to set it as system dot math will start simple player press dot get string, even though coins is not a string, but we will have to convert it at some point. We're going to call it by its variable coins comma, we're going to set it as a default variable as zero. That's why we don't need this anymore because we can art if there's no coins value already. So if you're a new player, I'm going to set it as zero. So that's really convenient. But the problem is that you cannot convert strength double. That's why we have system dot. Actually, that's why we have double dot pairs, double dot pairs, simply take a string and converts it to double. It's that simple. There you go. Now it automatically loads. And we can copy and paste this for however, how many of it variables we have. We got one there, we got one there. Okay, so now we're going to change all of these names to its variable, just so we don't accidentally load from the same coins data type or a data name. And we're going to make the click value start as one, we're going to cost start off with all this stuff. So we don't need this anymore. Basically, we're done with that. We just need a load. It's so convenient. It's awesome. Level zero, obviously. Oh, we forgot we've got two. Oh, levels are actually we forgot to delete this one. We don't need that one. Silly me. 255. All right, so we got all of our doubles that are saved. Ints are really easy. So we're going to just copy and paste this. We don't need the double dot pairs. And it's simply a get int. That's simple. And for default variables, we just need a number. Change that to that. All right, change the names. And you're all set. That's your load system. Save is a lot easier. So we're going to paste it in here. So what we're doing instead, we're actually going to start with player prefs and dot set string. So we're saving the string to the certain number coins. That's the name of it or the key. And we're setting it as coins, right? Is that all that needs to be done? No, we cannot convert and double the string. So what do we need to do to string? That's it. That's literally it. You just put the do string and it converts a double to a string, you can do that to an end to you can literally save int as a string if you wanted to, but it's recommended to do get or settings because it's just easier and it's more convenient that way, I guess. So we need to do this six more times. One, two, three, four, five, six. We need to save each one of these variables. And there is the save. So next are ints, ints are also really easy. So I'm going to copy this. We're going to set int and we don't need to string because it's an int and we're done. That's it. It's that easy. So I have to go in really fast. Basically, I'm just setting all the names as, as this. So if you still don't understand what's going on, I'll review. So for save. So player prefs, the class has a method called set string, which accepts a name, a string, and in a value, which is also a string. So set string, set string basically accepts another string or two strings coins and whatever coins to string is. So the number converted to a string. All right. And basically it creates, automatically creates a document for local save data. It's like an XML, I think. Locate somewhere on your computer. And it looks like this. It's like coins. That's the name. And coins, whatever it equals, it's like 300. It literally looks like that. So set string basically adds this to the documents. And if it already exists, it changes to whatever it needs to be, whatever this is called. Set int is the exact same way. So, but instead of a two strings, it's a string and an int, which is this right here. Load basically does the same thing. It finds the key coins and it finds the value and it sets it and it just returns it basically. So get string returns a string, which is found right here, which is zero. And when we parse it, it converts this to a double, which sets it to coins. That makes sense. So now, starting now, we will be able to automatically save and load every time we play the game. So we're going to play it. So everything should look new. But now when we start clicking or buying upgrades, let's see, buy some of these, or buy some of those, buy some more of those, buy one of those, maybe one of those. Hey, might not maybe two of those, you know, so we got some data right here to save. Right. So it keeps saving every frame. If we exit and then load it, we should have all of our progress. There you go. Save and loading. That's the that's really that's the depth down to earth basics of safe loading. Can't get any easier than this. But it can get a lot cleaner than this and a lot more optimized than this. This is just really easy to understand. And this is only for unity, just letting you know, because this player presses unity's class. So anyways, thank you guys for watching episode five. I think I'm so fired. Next one will be prestige systems, I think. Yeah, I think I'm going to attempt to do prestige systems the next episode. All right, guys. If you guys any suggestions, comment below. See you guys in the next piece.