 Hello guys, Crypto Grounds here. Welcome back to another C-Sharp Idol Game Tutorial video. This is episode 27 today. We're going to be doing the highly requested offline progress video. And I'm going to keep my hat like this for as long as I can. But this has been highly requested even though I already have a video on this on the Clicker Heroes video. But we're going to add it in here. Because someone also asked, am I going to publish this on the Play Store? Since I'm going to be doing a video on building your game, sure I will. Hopefully it won't get bombed with dislikes or one-star reviews. Because it's kind of not a finished game, obviously. But we'll go ahead for it. If you're new here, make sure you subscribe my channel to our notifications. Check out my other videos in this corner right here. It's the little I icon. And like the video if you enjoyed and comment your suggestions below. Alright, let's get on with it. So I can't exactly remember the whole entire process. So I will be looking at my other script just to make sure I get this correct. And I cannot deal with this how like this. Because I just go like this in order to see if that doesn't work. Okay, so let's go to our scripts. Let's create an empty object. And then we're only going to do this for Earth only. So we're going to call this offline manager. So this will be for both eventually. Or I'm only going to do Earth, but I'm putting this outside because it's not just for Earth. It's for you to expand. So we're going to do offline manager. I'm going to create that new script. Also, I finally got a new chair. No more squeakiness. I can lay down. So nice. So first we need our, and I should, why is this so laggy? Okay, but we need to import our unity engine dot UI namespace and our break infinity. Because we're probably going to use that for our math related stuff. And actually let's make a pop up real quick for offline. Just the basic one. So we have canvases for these. This can just be a game object. So let's create create empty in our main canvas. And this will be called offline pop up. No, I don't care if it's complete. Okay. And then we'll add an image component. Okay. So now I'm just going to create a bunch of texts and I'm going to kind of skip this. So you should know how to do that at this point. If you don't know, then you need to go back to the first episode. Kind of review the basics. Also, another thing I just did, I'm getting rid of all these rec transforms because we really don't need it. So all of these have a rec transform. Since these are not game objects, we don't need them. And we just reset the position back to zero, zero, zero. There we go. We should not have these in the way. I think this rec to transform can also go because it's a script. So that's zero, zero, zero. Cool. Now. I still have the square. What's the square coming from suffering? Now it's from the canvas. Okay. There you go. Now that square is gone. I just basically took everything out of the main screen and made this stretch to the entire canvas. The entire parent canvas. Okay. So I made our little pop up here. We have our welcome back time. We have our time text right here, which to get this color effect, you have to have rich text on like that. And all you gotta do is put color and then your hex code or you can just do like red, for example, to make it red. But I'm just doing this hex color for the light blue effect. And also I didn't do light blue because it doesn't even look like light blue if I do it. Maybe baby blue. I don't know. It just doesn't really look right. If I do blue, it's just, you know, regular blue. So that works in our favor. We just turn on the rich text. And yeah, like that. So this will be our seconds, minutes, hours and days. And I'll show you how to convert that into or how to take your seconds into this. It's in format it and our away gains and our okay button. So let's get on with it. So we first have our time texts. We have our public and that's not what I wanted public text time or away text time away text. Let's do that. And then we also have our we have our gains text. Or this is just going to be Earth gains text because we only have like we're doing that. We're only doing this for Earth right now. If you plan to expand it, that's up to you. Okay. So we need to create a few date times. So our first one is going to be a current time. And we will use public date time old time. Because when we basically how the offline progress work is that it's saved like on save. It saves the current save time. And then on load that save that current time will be marked as old on load. And then the current time will be the time of the load. So then it takes the difference and that's basically your offline progress. Right. It's not actually playing the game offline. I feel like that's what some people are confused about is that it's actually playing while you're gone. But no, it's just saving the time from your last session or the last time it's saved. Now the issue with this is that people can time cheat. So that's kind of an issue now. You can use server related stuff, but I don't want to get into that. And that's not really something I'm too concerned about. If people want to time cheat my games, go ahead, screw you. That's not, I'm not going to do anything about it. If you're that bored of my game, then might as well just not play it. Like, I honestly don't care if they're going to cheat, then you're a little loser. I'm just not going to just not going to do anything about it. All right. But that's up to you. Otherwise, you could just get time from a public server, which is a little difficult to do. If that's a request, a higher, like a high requested thing that you guys want me to do, comment that below and I'll be sure to do it. Because again, I'll do whatever you guys want me to do. Okay. So let's get on with the save thing. So we need to make, okay, we need to load our offline production. So make sure you pay attention to this. Okay. Every single line here matters. And before we do this, we need to go to our play manager or player data right here at the very top. This is for offline, but we're going to create an integer or an int. It's going to be a bull and it's going to be called offline progress check. So basically the first time you play the game, it's not going to show this. This will be false, right? But once you save for the very first time, the progress check will be set to true. So in full reset, we're going to set it to false. Okay. So now in load offline, so we're going to make sure if we need to get our game in here. So let's do public idle tutorial game game. And then in here and if statement will do game dot offline progress check. Oh, it's game data offline progress check. If it's true, then we will start loading our stuff. Right. So if you guys have like noticed this right here in your save system, this is exactly what it's for right here. Okay. This is exactly what this is for. Right. So before we continue, let's uncomment this out. Hopefully you still have it. If you don't, that is okay. I think that's the only thing we had to take out. Yeah. So make sure you have data offline progress check is equal to true in your save player. And yeah. And honestly, we can make it so that if it's not true. So if it's not true explanation mark. Okay. So we're going to set it equal to I only want to set it only if it's not true already. So we can just do if data dot offline progress check is false. Then we set it to true. So then we just don't have to do that over and over again. Cause that's just overdone and call. Okay. And then in here we're using player prefs to save our save system because it really doesn't need to be exported or anything. So we do player prefs dot set string offline time. And then we set that now we're going to set that equal to date time dot now to binary to string. Basically we're converting what the current time is when we're setting it. And we're going to what we're setting like we're saving that current time. That exact moment, including man, I think it goes up to milliseconds. I think that's the smallest unit of time for that. But basically we're just converting it to string and we're going to save it to our player prefs. Okay. So this will not be interfered with our full reset system. Cause really it doesn't need to be exported or imported or saved in the way we handle the rest of our data. Okay. And now in here we need to load it. So we're going to do var temp or we don't need to do temp or going to do the temp offline time. You can call it whatever you want. And we're basically going to convert this we're going to do player prefs dot get string offline time. So now we're loading it right. We're not done yet. Okay. So we have this but we need to convert this into a 64 bit integer. So we do this by doing convert dot to int 64, which is a long. Okay. So now this variables is the same thing as a long. Right. And if you haven't checked out my variables crash course video make sure you check that out. It will be in the playlist in the icon right there. Okay. So now we will use this. Okay. So I just realized that we don't really need this old time right here. Okay. So we're going to set a temporary variable old time. We're going to set it equal to date time dot from binary temp. So now remember so again I don't exactly know it's temp offline time. So now I can't exactly remember how this all works. Okay. But remember we did to binary right now we're doing from binaries converting it back to a date time. Right. Okay. Because what basically to binary we're basically setting it to a bunch of zeros and ones so that we can make this serializable. So then we can trance or save it easier because if we load this I mean honestly it might do the same thing but it will save as a string instead and we don't want that. So we convert to binary and then we do from binary and we make sure it's a date time. Okay. Because date time is not a string. Okay. So this variable is the same thing as a date time. All right. Next up we need to get our current dates. So our current time or our current time is equal to date time dot now. Simple as that. And honestly we can get rid of this here too. We can just do of our current time. Okay. And now this will even enable if you've been offline for a second. Simple as that. Right. Okay. So now we need to get the difference between them. So we do var difference which is going to be our offline and we do current time. We do. So we can't. So if we try current time dot my or minus old time. It won't really work. Okay. So this is this seems like it would work but we actually have a special method for that. We do current date dot subtract. And then we do. Oh, okay. My apologies. So we do current time dot subtract and then we do old time. Okay. So the reason why we got to do we got to do current time subtract old time is because date time is not like a single variable. It's a class. It's an object. So in order to subtract these properly and make sure we get the right times and dates correctly because if we subtract two months from five months, you know, it's it might look a little weird because not all the same, not all the months, not all five of those months are going to have the exact same amount of days. Right. So this method handles all that for us. Now we could just do days mile, we could do all this ourselves, but I do it when we have our subtract method, our date time dot subtract method that can do it for us. Okay. So now we need to create a raw time. Okay. So what I like to do is that offline progress, I tend to not do one on one. Right. I tend to just divide it by like 10 or 30. So every 30 seconds is a second of real gameplay. Now I wouldn't do anything beyond that. Right. Because that's very little. Okay. So we're going to set raw time equals. So now we're going to convert this to float as well. We're going to cast the float, but we're going to do. So what we do here is difference dot total, not total days, but total seconds. Okay. So basically this calculates the total seconds between the, the previous save and our current save what we're loading right now. And that gives our raw time, which we will use to get offline progress. So this is pretty much it for the offline stuff. Right. So this is just offline time management. Okay. Hopefully that I explained that well enough now. I can't exactly explain every single little thing, but hopefully I did my best. Okay. So in here, we want to have, so we have raw time. We're also going to make, let's do offline time, which we're going to do raw time divided by 10. Okay. Okay. So let's start with our UI. So let's do with our time away text. Oh, we also need a game object. So we have a game object offline popup. And let's make sure we close that public void close offline. And then in here, we do false. Okay. So now for a time away text, it says, you have been away for, yeah, you were away for, so I'm going to do dollar sign as loud. I'm sorry. So we're going to dollar sign, you were away for, and then new line. Let's go back to here. Let's copy this color thing since we already have that down. So we have our new line. Oh my gosh, shut up. And then we have here, we have our color, our color tag, our HTML tag. And we need to put brackets or curly braces where our time is right here. Okay. So we're going to put raw time in here. So right now this will only show the second. So we get a format that. Okay. So then in here, in order to get the to format the time correctly, we need to do time span timer, and then just for example, for a name. And then we're going to do time span dots from seconds. And then here we just put raw time. Okay. And now if we put timer in here, we can format it the way we'd like to. So we will just do date DD for day. So that's two digits of days. So if we put three days, that will be 0, 0, 0, or how many, if you have 100 days, it'll do 1, 0, 0, right? There's just 10 days we'll do 0, 1, 0. I'll kind of show you once we demonstrate that. So we're going to do double backslash because we can't just do backslash in here. So in order to get the backslash to actually be in the text, we have to do double. Okay. So then we do our double backslash and double backslash SSS. Okay. Actually, no, we just need the colon. So in order to get the colon. Okay. I think we do double backslash like that. Is that it? No, it's just like this. Okay. But a little lesson for you right there anyways. I think this is correct. Nope, it's not correct. We actually had it. Double backslash, double backslash, double backslash. Okay. Like that. I think that's just for the variables. I'm not sure. I'm not like very good at the formatting, the string formatter inside this kind of stuff because it's really different when you do dot two string. Okay. Now we got our time away text. What about our gains? What about our gains? So let's just make a variable or let's make a big double for now. We're going to call this gains or coins gains. And we're going to set that equal to so let's go to our main script. Okay. So we have our total coins per second, right? So this is kind of a little issue here is that if we do this before we actually calculate total coins per second, then we have an issue. So what we do here is that we call total coins per second after load player. Okay. We call that we're going to also do something here too. So we're going to call it at start. And then here we're also going to call game dot game dot total coins per second. Is it private? I think it is. Yeah. Let's make that public. Okay. So actually we can just, we don't need to put that there. Okay. So our gains will be total coins per second times, times offline time. Okay. So now every 10 seconds is one second of total coins per second. Okay. That's pretty much it. And then what we can do here is game dot coins per seconds. So actually, before we do this, let's comment this out, but we're just going to do game dot data dot coins plus equals coins gains. Okay. Now we're going to comment this out because we don't want to get a bunch of NAN just in case this doesn't load the way it's supposed to be. And then we're going to have our earth gains text and it just says you earned. Okay. Oh my gosh. Windows dollar sign you earned. We're going to do a new line plus curly braces coins. And then in the curly braces we're going to do coins gains. No, we're going to do game. No, it's methods methods dot notation method. And then in here you put coins gains and then we do F2. Cool. Okay. So it should work. Hopefully cross our fingers. So at first it should not, we should not get any single form of offline progress at all. I don't know why I have this in here. So then in here we get our offline manager button. And this is just the close, close offline, which is this click button right here. So we should rename it this to close offline. Okay. And then our offline manager, we drag our game object right here. Our game is the, I think it's just, it's game manager. Yeah. And then we have our time away text and our gains text and this should work. So let's just toggle this off so we can see if it actually shows up when it's not supposed to. Cool. What is this right here? Okay. Well, I forgot one thing. We're not actually done with this. So it doesn't even load offline production. So, okay. Where is this error though? Kind of curious. Okay. It's the total coins per second. I see where our issue is. Okay. So now in here, we need to call our offline. So we're going to create an offline manager game object or call this offline. And we are going to load offline manager last or load offline production last. Okay. And basically we're going to run all these total coins per second after these run. Okay. And then our offline and hopefully that should work. Okay. We're getting no reference error. Okay. I see why we forgot to drag our offline manager. And the reason why we weren't getting spammed because it only happens once, which is on start, let it save, let it do its thing. So we should be getting nine per second. So if we are off for 10 seconds, we should get nine dollars, nine coins. Has it saved yet? Oh, it should have by now. Yeah. Okay. So now let's wait 10 seconds. Finally a nap. Times up. I don't know how long that was, but we'll see. Oh, we didn't get our offline progress. What's wrong? Okay. So our offline progress check is not working. Okay. So our offline progress check is not working. So it just says it's false. Okay. Well, I'm just going to get rid of this if statement because I don't know why. I don't think that's it though, but let's try it. Let's move these to the outside. Maybe that could be part of the issue. I don't know. Mine isn't at least. And is it the right offline time? Yep. Yep. Okay. That should be good. Set string. Okay. Well, let's give it a shot. Oh, we got our offline progress. Woohoo. So we got 22 seconds. So if we do the math for this, 22 divided by 10 is 2.2. But if we do 2.2 times nine, we get 19.8, which is pretty close. Of course, this is probably rounded up. There's our offline progress. So does this work? Okay. I see the issue. We forgot to remove this comment right here. So make sure you remove it so we can re-add our coin gains to coins per second or to our coins. Okay. So now it should work. So we were around 80. So it should be around 100. Woohoo. It worked. Okay. Cool. Does it close? Yes, it does. Cool. We're done. Very easy, very basic offline progress system. All right. Anyways, I hope you enjoyed this video. If you did, make sure you leave a like. Oh, every single like appreciates me. Check out my channel. And if you're interested in future merch, make sure you leave a vote. I have 50 votes. I will release merch for 1,000. If not, 5,000 it is. Anyways, I think we can do that. So subscribe if you're new. Turn on notifications for future videos. Check out my other videos in the icon corner. Comment your suggestions below and anything you want. Anyways, have a good day. Peace.