 Hello guys, Crypto grounds here. Welcome back to another unity C sharp auto game tutorial video This is episode 38 and today we're gonna be doing stuff with our offline progress such as upgrades If you enjoyed this video, make sure you smash that like button subscribe to my channel if you're new turn on those notifications and check out my other videos in the top right corner and Comment your suggestions and other questions down in the comments below if you haven't joined my patreon yet, make sure you do that any single amount of Money per month is highly appreciated. We are too away from starting the anti-matter dimension series And that is a series that i'm going to go along with this series as well Kind of like I did for the clicker heroes. I'm just going to do it separately, of course So yeah, make sure you do that and also I have a vote poll thing on my channel page In the community section about my future merch. So make sure you vote for that. Um, we're going to be dealing with our upgrades spoiler uh Thanks arm barts. All right, so Let's head into earth and our upgrade screen. We're just going to add another upgrade Okay So let's see It's our list right here. I'm going to rename this to upgrade list We have our critical click right here. I'm going to turn off this mask so I can see We're going to do this in the rebirth screen Or maybe pressed each screen. I think we should do this in the pressed each screen Okay, so this will be a prestige upgrade Okay, and this will be our offline And let's call this um offline progress Is plus one percent better. Let's make this pricey Let's make this cost like e4 or something like that gems Okay, cool. So now let's hop into our upgrades And I think it's prestige upgrades actually Is it just our prestige manager? Let's hop right in Okay, so we have um We already have our buy upgrades. So we just got to build on this. So let's start from the top Okay So we have our so we need to expand this uh increasing this the four isn't going to do anything We're going to have to do this to unity but for the sake of knowing how many texts we have I'm just going to create increment this number Um, okay, so now we need a cost Cost four is going to be I think what I do like e5. I did e4 gems So it's going to be e4 gems and well, let's just double this Or let's do 1.75 times every upgrade And let's Change that to prestige u level four We that doesn't exist. So we need to add that real quick. So let's find this Right here with our prestige upgrades So to add this public int to our player data class Okay There we go. And now in our constructor, we will set this to zero Okay, I think it's safe to close every single Script except for this one Um, okay. So yeah, we need to initialize each of these cost array Size four we need to add our string. So this one is offline progress Is plus one percent better, I think is what it was Yeah, that's right Offline progress is plus one percent better Okay Okay, so we don't have to adjust anything here because Yeah, this is based on an array that we which is The cost text it's based off of this right here. Now this can be any array Right here because they're all the same size But I just did cost text off length, which is four So this will iterate from zero to three zero one two three And I'll stop at four because three is less than four Four is not less than four obviously If it was less than or equal then Then it would iterate two four and that would not be good because that'll be a ray out of bounds Because of our limit is three zero one two three size four array Okay, so let's add our third upgrade No, this is our fourth upgrade Okay, just it's pretty much just replacing and copying pasting at this point Because it's the exact same thing We can make that private. Okay. So now we need to add on to our array manager And actually I just realized that we changed our save system so it can um It can handle arrays better But I'm for the sake of having this already. I'm just going to keep adding on to it Even though I really should um I should just do arrays there Or a list at least Okay Should we try that let's try that let's try something new Because I feel like if we just keep doing this it's just become a mess. So let's try it Let's load up our player data class wherever it is right here And let's do Levels Why do we even have this is this even oh, I see now Okay, well, let's replace this with a list Okay, we can close some of this Where's our prestige upgrades? Okay, it it just disappeared. I swear Oh, there's two prestige Okay, I see now um, okay, so we're going to replace this with an uh a public list type int We need to import this namespace I think this is what is it boo.lang what is that? I've I don't know what that is Okay, there. I'm like, okay. That sounds more like it systems.collections.generic. I don't know what boo.lang is Okay, so this is gonna be our prestige you levels And that's gonna be equal to a new list type int Like that. Okay, we can get rid of this And we can initialize this with the size in here too, but we're just going to Change this to uh, let's see We're gonna set this equal to a new list size four. We can actually get rid of this here too Okay Capacity four. All right. So now let's say we want to add on two more uh upgrades so What we do here is that let's say this is four and we initialize it and well right now because we're not creating a new Player data constructor every time we load the game It's just going to be a size here. I'll show you an example Let's take this And I'm going to print this in run Okay, this is data dot print levels dot length. I think it's that length or count. It's one of those Oh, I didn't do that game dot data Dot prestigio levels dot length. Okay or count. Sure Um, I'm just gonna replace this with one for now. I'm just Because I don't want to get a bunch of red which we clearly already do Okay, let me just block this stuff off temporarily because I want to try something Because this is going to be a size zero Uh list I can guarantee you that's what it's going to be Oh, shoot. We do this stuff. Wait, okay Hold on Okay, let's run this Oh, it's a null reference. Okay. See this is the issue I I have with save system in general is that it's this right? It's not initialized So I feel like I have to add this Right here Let's see what happens No, I don't want to do that I'm gonna try that let's see what happens I'm curious. I doubted the work Yeah, just as I figured. Okay. Well, this is where we do Um, I thought we had a check method. Don't we do don't we have that? Okay, so this is what we're gonna do. I'm gonna create a method in here We want to check to see if this is null because if it is then we need to initialize it. Okay Okay, so we just simply do uh, let's create a method called public void check Objects, this will be anything where it requires and is like, uh It requires it for it to be initialized like we do for lists arrays and etc So and here we simply do if Prestige u levels is equal to null Then we create it Okay, so now it should be initialized the thing is that we need a specified size. So let's do this inside our um specified Prestige manager. Okay So what we can do is So this will occur Okay, let's see. Okay. I'm gonna load up my main script right here I where we load our data. So right here We're going to do data dot check objects. Okay So we'll do that right after we load our player data Even after we create this player two And after we if it if the save file doesn't exist and it creates a new player data Then we don't we won't need to do data data dot check objects in this case However, if we add new stuff to a pre-existing save Then we're gonna have to initialize it. I don't I don't know any work around right now I've been I've been experimenting a lot lately and so far this is the best I can get to All right, we can close this now Okay, so in our prestige manager, we need to do some stuff in our start prestige. Okay, so let's say Um data dot Okay, we need to initialize because we're gonna use this Often I hope I suppose I suppose. Sorry. I cannot speak today Okay, so if data dot prestige you levels dot count We can also get rid of that too. Maybe Um, if it's not equal to let's say we want our list to be four Okay, we want it to be a size four and now whenever we add another upgrade We just change this number to five because what we're gonna do here is We are going to have a for loop A four of our i equals zero And we're going to subtract the count or We're going to subtract four from the current count because we want to count how many We need to add how many empty spaces or upgrades levels we need to add to this list Okay And since this count would be zero It should do it four times obviously and we're going to increment this by one And we just simply need to do data dot prestige you levels dot add And let's just add a zero. Okay Easy enough I'm not gonna do that I'm gonna simplify this and make it one line Okay, so if the count is not equal to four Then we're going to run a for loop from zero to four minus the current amounts of upgrades And we're gonna increment it by one And then we'll just simply add a new item every time. Okay So now let's say we want to subtract a level. So here, let's run this and let's see what we get Oh, okay. So we have an issue here. It says the count is two So that's not good Okay, so it looks like it's only adding in our two to this list because the current count is zero So we're doing four minus zero And I don't know that's really weird So I guess the only way I could test this is by seeing how many times it is Going so let's just add a print i to this. This is just debugging 101 Okay, so it looks like it's only running Uh Two times. Okay interesting I see why Okay, this makes complete sense So the reason why this happens is because count is always changing. So what it's doing is that it's originally four minus zero Right, and then it's four minus one. So that's equal to three And this is equal to four And here here, let's add some comments Okay, so it's zero minus zero or four minus zero, which is four and i is equal to zero in this case Okay, i is equal to one in this case And then our next one is four minus two, which is equal to and i is equal to Two now it won't call this because i or because i is equal to This statement right here. So it stops and that's why we see zero and one only it only calls it twice So how do we do that? Well, we make a temporary variable And we set that equal to uh, this right here Data dot proceed to you levels dot count and we replace it So now it shouldn't change and it should Function correctly and we can make it to a variable Okay, so I know for a fact this is gonna work. I can get rid of this print here and clean it clean it up a bit Cool. Okay. So it should work now So now lesson learned for arrays. No, not arrays for four loops If you didn't know is that the variables do change outside of the um It still affects this um in here in the for loop, right if this is changed this also changes Uh, I imposed the play the pause button said the play button Okay, so it should print out four now Cool. So we know that works. So now let's say we want to subtract, right? Uh, so let's say we want to bring this down to three. So how can we do this? Uh, let's do if data dot prestige new levels. Okay if data dot levels dot counts is not equal to three uh, so now We need to subtract. All right We only want we only remove it once remove Index. Okay. So now what we do is that we replace this with remove at index We're gonna start at the maximum. So how do we know this? Obviously we could put three in it Okay, but for the sake of this i'm just gonna do Uh Is that right? Returns the maximum value. Oh, no, that's not it dots Capacity gets the Okay, I'm I'm done. So what we can do is return the uh, we can do i equals Counts minus one Okay And then we do Uh, if i is greater than three i minus minus Okay, so now this is working backwards We're basically just deleting the bottom ones and working our way up. Okay So now this is very very basic Um list such as like level one level two level three If it's more complex than this then you're gonna have to customize it on your own and Kind of figure that out. Okay Uh All right So this should return Okay, we can do that This should print out three now. Hopefully crossing my fingers Because it's only going to iterate once And actually we can set i equal to temp count. Let's do that Okay, save it head to unity and we'll run it Oh, it says zero now Okay, so that's an issue. It's not saving the size. It's not okay. I think the reason why This happens is because Here let's just Let's create Let's okay, so the reason why this wasn't working is because we forgot to save it before we actually did this So let's do Um If i is less than four We know we want to only add well, we already know it's zero. So let's just do it anyways Okay, sorry if i'm really confusing. So let's just do that Okay, so now you should create a four size array or list And then we should subtract one at the end of it Okay, if this doesn't make any sense. I'm very sorry. I'm trying my best This is what I hate. I hate about save systems Okay, so it's not subtracting one now. That's an issue Okay, so let's see if the count is not equal to three. So we know that's true Okay, so it grabs this counts which is four It says i equal to Three If i is greater than three Oh, I see. I think we need to do i equals greater than three For this situation. Okay, let's try it. It should work now Because less than is the opposite of greater than equal then, okay Four three perfect. Okay, so let's try to save this Let's go to game manager. Let's save this. Okay Now let's get rid of all this Get rid of all this or let's undo most of this so we can have This work properly Yeah, okay Let's Get rid of that see if it actually loads in four and it should I'm scared. Oh, yes. Okay. It loads in three. It saves. We know the save system works with a list. Okay, cool So that is how we Um add and subtract Non-needed or needed levels. So we need four. So let's add on to this We need to bring this back real quick Okay, so now you just keep this at the beginning or at the end of your start Uh start method, okay And you do this for any array you want. All right. So if you either want to subtract levels or add on to levels This is where you do it. Okay. It's going to be one or the other right? So since we want to add we want to keep this here For all users and let's say any user that plays this game They're going to start with zero levels So we need to make sure we add on to four because that's what we want. Okay So we should know this works. We can get rid of this save it Okay Now we have our upgrades we can come back to here So let's replace these ones with data. Oh, it's going to be game. Yep game.data.pressedeju levels at index zero Cool. Now we're using arrays So this was really annoying to make I understand if you prefer the levels like I was doing before go ahead I would only use this Method if you understand it and if you're comfortable with trying it Can I try this? I thought that would work Okay, so now I'm running into an error where um Indexer access returns temporary value Ref arguments must be an assignable variable field or an array element Oh my gosh, what is that? Okay, so I didn't know this but as I'm reading apparently we don't need this for um A list because list is an object and we are already pretty much um sending the Let's see. Well, what was it called the reference of this field to this method right here So we don't need this ref int level here so we can get rid of this And this should fix our issue and this would work just fine Okay What Oh, I have an idea. Let's do this Maybe let's bring back this ref And then in here We're just going to do an int array Will this work? Oh, this is a list. I forgot. So this is a list type int There we go that works and then we need our index here. So let's just put this in here And then into id Okay And then here will be list into id. Oh, we already have an int id I'm just gonna put out for or I'm just gonna do level Okay, so now what we're gonna do we're gonna take out this array. We're gonna replace it with comma one We're gonna do a print or an integer parameter instead to access the list inside here because I mean We that's what we need to do. So again, this is only for doing lists. Okay Otherwise, you don't need to do this. You can just continue how it was before Just copy and paste And honestly our array manager doesn't even even need to be touched anymore Because we have our levels array, but we never Technically use it and see here it says levels here What we can do here instead is data dot prestige. No No Game dot data dot prestige you levels at index two Cool, so we can get rid of the levels in here You can also just get rid of this array in general Fix the reds. Okay, so this one will be a data Dot prestige you levels Alrighty, so that works much much better Uh upgrade manager has a red or is this red? I can't find it Oh right here. Okay, so this is game dot data dot Prestige you levels instead. Okay, because this was our upgrade levels Now back to our main script. We're getting more issues. This is the same thing It's just data dot prestige you levels Uh data dot prestige you levels Cool. And now back to our rebirth manager. I got rid of all these So for rebirth what I'm just going to do is take data dot prestige you levels and set it equal to List uh here actually So we don't have to change this multiple places. Let's create a Sorry if I'm hopping around a lot Let's create int And this is going to be the prestige you level Size, okay And we're just going to set this equal to In the start method, we're going to set it equal to four because this is our size that we want Just so it can stay consistent We can even do this in the cost array too Okay, and now in the rebirth manager we do Uh new list type int And the size is Uh prestige Game Dot prestige Dot Prestige you level size, okay So now when we prestige all we got to do is just create this list all over again And it starts over with a bunch of zeros, okay Cool. I think we're safe Anything else we had to save I don't think so Oh, this is the wrong one Um Yeah, I think we're fine and honestly the only thing we need to do in here Is the cost that's it Otherwise I think this is fine Okay, so now we have our upgrade actually done We need to do the offline progress. So this is level three. So let's hop into our offline manager And we just need to make this progress better. Okay, so offline We're just going to multiply offline time not raw time because we want to see how long we've been gone for So we just multiply all of this by Game dot prestige Now the reason why we're doing game dot prestige is because I really don't feel like creating a public prestige manager object When I can just access it from game And we're only doing it once so it's kind of just Pointless if we were doing it Numerous numerous times then yes, I would put public prestige manager prestige Otherwise, let's just we're only doing it once so let's just do game dot prestige dot Uh, no, this is actually data. I just realized never mind then this is game dot data dot prestige u levels at index three Okay, we get rid of these redundant parentheses And so this is only by level so let's multiply this by 0.01 for 1% Plus one and just a double check We we don't need these because we're adding to This this is a statement just for order of operations Okay, so now every level we buy it should multiply by 0.01 and we get that boost Okay Anything else we need. I don't think so Okay, I think we're good Let's hop into it Okay, so let's go to our prestige manager And see we still need to increase these by one Okay, so let's grab our offline upgrade button text which goes here Our progress bar And our smooth progress bar right here And I think that's it. Let's save it So let's go to prestige Cool, that looks good. So let's give ourselves some gems It's the the smooth progress bar working. That's good. Let's Buy that see if it works Oh, right. I forgot one important thing Let's get out of that Uh our upgrade button right here It still buys the the third upgrade. So we need to increase this to id 3 Save it and play and it should work Okay prestige Buy cool. So it increases by or it multiplies by 1.75 just as I mentioned Up here So we know that works the level works. I can buy that see it's all different levels. Cool Now it should work. So let's just buy this a ton Here can so the Oh, you can see list. Okay, never mind. I was about to say the sad thing is that you can't see list here But I forgot you can that's jagged arrays where you can't see this. Okay. So let's buy let's just give ourselves 10 Maybe a lot like a thousand So this here is a hundred percent. So we should be getting two times more rewards And let's see. We don't we're not getting anything per second. So let's get some upgrades Okay, so we're getting 3.2 per seconds. Okay So normally in offline We are getting 3.2 e3 per second because we're dividing it by 10, but since we're getting a hundred 100 percent more Or not a hundred percent more This is a thousand. Okay, so let's see Am I calculating this right? So this should yeah 11 times more. Okay so This should be Just about accurate. This is about So basically we're getting a little more right now Per second than we are getting online time. That's kind of funny. So let's get out of this It should work And we can calculate this too Okay, so it looks like it worked. So we're getting 3.2 e4 per second We multiply that by 13 seconds Okay So now we divide this by 10 Now we get this number We multiply it by 1000 times 0.01 and that should be about right We're close close enough Okay I hope you guys enjoyed this video and I hope it was helpful if it was make sure you smash that like button Subscribe to my channel if you're new comment your suggestions and everything down below Check out my patreon patreon.com slash crypto grounds. Check out my other videos in the top right corner Thank you guys for sticking around and I'll see you in the next one. Peace