 Hello guys welcome back to another idle game tutorial. This is episode 8 part of the idle game tutorial series today We're going to be doing by max Okay, sorry, so basically the problem with our upgrades is that We're at the point where we can buy We're at the point where we can buy lots of upgrades And a lot of us don't want to click that much right? So last episode we did promise bars, she didn't see What's the neat? So anyways, we should really add some by max Buttons, so we can you know prevent having to click a hundred times so this is more of a Kind of a just like okay here you go This is how you do it kind of a thing rather than like a deep explanation because I'm not very good explaining math Just simple as that and the math equations of all involved with this. I did not I did not come up with them I used I Used congregate for that So for those who want to say you need us you need you should site them on this Yeah, this is the site. I looked off of It's really good. It explains lots of math stuff. I basically use these equations this one calculates the The max cost this is how many you can buy and The math equation will be using and we have been using is this one right here So it's blog congregate calm You can just search up the math of idle games part one congregate. I'm sure you'll find it anyways Let's get on with the by max. So first we need to create a button So we're going to do copy and pastes click buy or just click every one We're going to call it click upgrade one max All right, so this is a simple By max and we can calculate the count so we'll do that. So that's how many we're gonna buy The cost isn't real the display cost really isn't that important since we know how many coins we already have So therefore we all need the how many we're gonna buy All right, we'll just put that there put it wherever you want. I'm sure your user interface looks different than mine Anyways Let's get into the code We don't need to create any variables here Basically all of our upgrades stuff is ready. We just need to create a method. So we're gonna go all the way to the bottom Actually, we're gonna go under the by click upgrade one. So we're gonna call this public void by click Upgrade one max so we just created a new method and So there's two ways you can do this Here's the really inefficient way Change this if statements to a while loop now If you just want to end the tutorial with this sure go ahead you can do that right now But if you want something a lot safer Then I would continue Basically this while loop is only good for if you need to buy a few hundred upgrades if you have to buy Thousands to ten thousand stuff This is highly highly not recommended because it will just freeze your game until it's done processing all 10,000s and etc runs. So this is good for buying like small upgrades. It's really that's really easy But I'm gonna keep this to the side just so you guys can use it I'll label as Not safe All right, so this is the not safe and This will be the safe one and this one is a complicated enough for me to not understand how to explain it So I'll do my best. So I'm gonna copy and paste My by max method from my game There you go. That's it. This is all it except we need to change lots of things So basically every time you buy an upgrade we multiply the cost by 1.07 We have two formulas right here. The cost is how many times it can upgrade from the current cost and level So basically it's got to calculate how many times it can multiply 1.07 and Before you can't buy anymore All right, so this is our base cost for us it would be Whatever we set it to Click upgrade cost one. It's 10. It'd be 10. So what's changed that to 10 or quick? Var C. So this is our currency for us. It's coins and R is our multiplier Hours is 1.07. We're gonna change it to that And K is basically the stuff we're buying So instead of drones right here, we're basically gonna do Click upgrade one level Because we're basically count we're trying to the K We're trying to find like how many we already have which is what this formula tries to calculate So we have a bunch of big doubles here Since we're doing doubles just do system dot math Replace all the big doubles there you go So now we have our equations done again var n. This basically calculates how many you can buy Which is which is really useful for right this right here and You know what for this we're gonna we're gonna do we're gonna do public double because we're gonna return our end Actually, no, we don't want to do that never mind. You know what I said and the cost basically just calculates how many How much the total cost will be All right, so then we have our if statements, which is easy You just get the click upgrade one Frick cost and We want to check to see if it's greater or equal to the cost And we are adding to our level my germs, which is the plus end right here Cannot oh shoot. This is an inch. I forgot you got to cast this as an inch since this is our levels an inch Which is why I recommend using all doubles in the first place because you have to do any casting and our Coins will be subtracted from the cost just like our normal upgrade and Let's see we need a We need to add to our click value plus equals and We don't need to cast this and click value is a double and that should be it It looks complicated, but you really don't need to know what the math is in order to use this I promise We could simplify some of these parentheses To make it look cleaner and Yeah, that's pretty much it. So we're gonna be using this one Yeah, so basically to get this text right here. We're gonna make a new one. So I I did I did need to make something right here I forgot So last episode eight. We're gonna make a new text We're gonna do you click upgrade No, okay Um max text and This one's easy because we just need to update it with the rest of our stuff episode So the text is simply going to be by space max parentheses plus parentheses and in between this We are going to have our A little equation right here. So we're gonna have to Copy all this but what I would recommend is to make a new method. So basically what we can do is public double by click Upgrade one max count. So basically this will give us how many We just need to copy this and we need to return in There you go. So now we just need to add this to the text We add this method which this literally will just return as a number because it's a double method So this should work save it Okay, so now we have to change our method at the button which is the By click upgrade one you want to go to add a good tutorial I'll try a game and change to the max and We added a text. So let's drag it to our game manager script anyways Save it again like usual. You should always save really often because it can It can bite you in the future. Trust me. It's done in many times. Anyways, let's run it. So right now We can't buy any right now. So We're clicking away we're not getting anything. So let's first each get ourselves some gems to make it go faster So here's a good example to use the This right here So see how this is adding up right now So I can do by max and it buys seven upgrades. Oh I forgot one thing. Sorry We've got forgot something very important if we're going to change the cost base on this right here We're gonna have to do it here, too So this is easy It should be so we have our little equation here We are going to The cost is not going to be a constant variable anymore This is all right So we're gonna change we're gonna make our own variable cost and Remember we need our system dot math Our base cost is gonna be 10 and we're multiplying it by 1.07 like we did here So now it should work. Oh Of course, we forgot our click upgrade level. Here you go So now you can copy this equation To get the cost. Where is the cost right here? All right, so we're gonna copy and paste this under the click upgrade one cost string We're gonna call this the Click so since we have this new variable right here. We can honestly just get rid of This right here. Why because our Cost is fully dependent on other variables and like I said in the save and load episode We don't need to save stuff. That's hot. That's dependent on others. Therefore, we can delete this I'm keeping the rest since I don't want to change all but just so you know that you can leave these and We can remove this right here, too All right, we're good to go We can move from our prestige Okay, we need to move this outside of the if statements so then we can do the cost This is easy to read to and this should be cost right here So if that was really quick basically, I just fixed some of the variables that didn't match and we have one more right here So make sure you have nothing related to that upgrade and You only have this So now the upgrade Cost shit update properly It looks like you're already saved. Okay. That's pretty fast All right. Here you go So now our Okay, why is this not? Did it not save I have a strong feeling it didn't save Yeah, it didn't okay. Nice unity. You're really cool There you go. Now it's updating so Now if we buy one here it updates the cost if we buy some here it updates the cost Which is awesome. So now we can buy five at five and it subtracts it all properly So, yeah I'll leave it on the code for you guys to look at since this by max is you know, pretty weird whack with math But anyways, thank you guys so much for watching this. I hope you enjoyed this tutorial Next episode will be Um Maybe advanced saving load. It's either that or Good UI practices because I feel like that's a lot of tutorial. I've never seen it to trial and good UI practices other than Just generic good UI practices, but this one would be good for just like IO games in general So, yeah, thank you guys for watching. Make sure you subscribe to hit that bell to get notified the next episode Hope you enjoy it. Thanks for watching. I've said that million times Yeah Got me in this party all up in a zone. How does Betty's trying to take away my cell phone like coming party? I've been trying to take you off my mind, but just can't get you off me. Keep it moving. They ain't worth it Yeah, that's what my father taught me. But for now, I'm going through the motions of letting go It's my mind selling me. Yes, but my heart really don't know your heart when I gotta know it yet I still see a glow so we had the hottest love. Why'd you leave me in the