 Hey everyone, it is Crypto Grounds here and welcome back to another video. This is episode 7.1 for the idle game tutorial series 2021 edition and today we're going to be using the two BIMACS equations we came up with in the last video 7.1 and implementing them in code. Okay, so let's jump into it. So we are currently in our project right now. I have created a brand new button. It's right here. It's just going to be our BIMACS button and we're going to create two methods. One will be inside of our method script. So let's open that real quick. And then the other one will be in our upgrades manager script. So let's start here. So let's create a method for our BIMACS. Okay. So currently it has no parameters whatsoever. However, let's take a look at our little equation here. So I used ASCII math to format this equation looks very nice. So let's start with that. Let me split this up. Let's implement our parameters. So we don't need a cost. We just need our base multiplier and our current level. So our base is going to be, well, we can either make it a double or a big double, but let's just be consistent and use big doubles. If you wanted to use less memory, our base mults and levels could be less than that. Like levels could be ints, our multipliers could be floats and our bases can be doubles. That's however you want to do it. I'm just going to keep everything consistent and use big doubles, but that's for you to decide. So we have a base cost, a cost mult and an int level. So let's create our equation in code. So we're going to have our big double cost. And this is going to be equal to base costs times and just write it all out. OK, so we have our equation. So the cost is equal to the base cost times big double dot pal cost mult and level. Multiply by our big double dot pal cost mult n minus one. And these two terms divided by our cost mult minus one. So we now need to implement our end. So this is where the other equation comes into play. And that's this guy. So let me write this out. Also, for this equation, we have C. So our C is going to be the currency we are willing to spend. So you want to add that as a parameter as well. So we'll just call that currency. All right, so here's our equation fully written out. And if you were to compare it to the ASCII version of it, you'll see that they are identical. So yeah, it looks like that. And there's some simplification we can do. So I've already done one and that is make this cost method right here, which is just the base times M to the power of level. We can do that here as well. So we can just replace this equation here or this part of the equation right here, base cost times big double pal, cost mult level and replace it with this method. And my end is an int and I also ended up changing the cost mult to a float just because I don't really think most people are going to have super large cost multipliers. And if that's the case, use doubles, whatever suits your needs. And yeah, so these two are the equations that we will be using. And if you want, you can press alt enter to import static members and it kind of cleans things up a little bit. And what that does is that it implements the using static break infinity dot big double at the top of your script. One last thing you can do is that if this is really lengthy for you as well, you can change the names of our parameters. So currency could be C instead. Our base cost could be B or M could be cost mult and our level could be L. This may be a little hard to read, but at least it's not super long like it was before. And you could just make a comment. So we have our equations done. Let's do the actual buying process. So we still want to check to see if our cost or if our currency is greater than this cost, because if for some reason your currency changes while this is running and you can't actually purchase this, we will get negative numbers and we don't want that. So we're going to do is check to see if C is less than cost. And if that's the case, we're going to return and do nothing. Otherwise, we're going to subtract cost from C and we are going to add to our level. And this will be based on whatever N is. So there's two things that we need to do before this is done is that these values aren't actually going to change the actual currency you have and the level. What we need to do is move these to the beginning. So we have CL and then our BM and then we add the ref term. So basically, we're grabbing the reference of our currency and our level variable and changing them directly inside of this method. We didn't have these ref terms. And if we were trying to change C and L inside of this method, it's just not going to do anything on the other side. And this is our by max method. That is all we need to do. Second thing we need to do is head to our upgrades manager. We need to implement like actually by max. So I'm going to merge the by max like all together and it will by max all the click upgrades, production upgrades and generated upgrades. You could split it up if you'd like, but I'm just going to do all in one just to make things easier. So I don't have to create more buttons. All right. So I have created a by max method with no parameters. And what we're going to basically do is for loop through all of the upgrades and call that by max method that we made in our method script. All right. So I have implemented the three for loops for our by maxes and we ran into an issue. Our error here is that index or access returns temporary value. So this is actually a temporary value and using the ref term doesn't change it directly. And we need to do something else. So let's head back to our method script. We can keep this by max method because if we were to have just a normal level that was either an array or just an integer, this would work just fine. However, we need to grab the list and do something else. So we can just copy and paste this and change this into a list. And on top of that, we need to grab the index as well. And we can just label that as I. So now we go to the bottom right here. And we are accessing the list at index I. And we're going to be doing the same thing for our cost equation. Now, if we were to head back to our upgrades manager. Oh, we have one more. Silly me. If we were to go back, things should be fine, except it's not. We have to get rid of this. After that, we need to add our index, which is just I. Oh, okay. I see here. Our production upgrade is actually a big double because our generator produces the production upgrades. I think it's it's been a long time since I've touched this. So not as to copy and paste this one more time, except with an interest. We're making a big double list. So and since our levels are not whole numbers, we don't have to cast this as an interest anymore. So our N becomes a big double and our cost right here. Once an int. So we need to copy and paste this cost equation, change our level to big double. And then we should be safe. And now if we go back to our upgrades manager, everything should be happy. And let's give this a test. So before we test it, we have to sign this by max method to this button. Drag your upgrades manager to the on click and select the by max method and hit play. Alrighty, so let's just get some stuff and if we were to hit by max, oh boy. Okay, so this is broken. This is very broken. I see interesting. Okay, that's not good. All right. So I kind of realized I did something really silly in regards to this buying stepped right here or this, you know, figuring out this equation right here. But in step three, where I add one to both sides, I added the plus one in the wrong spot. So you see that plus one right there? Well, that should actually be on the outside of this, you know, this fraction. So it should actually be right here. So, yeah, I did some testing and it completely broke. And it's because this is incorrect. So don't make the silly mistake. Make sure you check your math. And if you do mess up one step, you can do something wrong like I just did. So let's move this plus one, which I had to do for all of them. So give me one second. All right, so it seems to be working fine now. Let's see. Yeah, it should be working fine. It's just not updating the UI. So this is what the final equation looks like. So I basically just moved that plus one outside of the numerator inside of this log. So it's all of this plus one and make sure you change it for all of them. And if we were to go to our upgrades manager, we need to update our UI. So in which we just add that at the bottom and everything should be working just fine now. Sorry for making that math mistake. I actually feel really embarrassed about that because it's just a plus. It's it's literally just basic addition and I couldn't even do that right. But anyways, this should work now. So we can just spam this a ton. Let's just give myself tons of money, tons of flasks by max. And yeah, everything's great. Cool. So everything's in good condition. Let's just give us some of this. Cool. All right. So that is the by max is very powerful. And it's a great piece of quality of life to including your game. And I hope this wasn't too complicated. So I'm going to leave these up for a bit just to make sure you have all of them. And you may not be using this one right now. But later down the road, I guarantee you're going to be using something like this where you are taking in just a single integer level rather than an entire list. Anyways, that is it for this video. I hope it was really helpful. And if you enjoyed it and you found it helpful, please leave a like and comment your favorite fruit in the comments below as it really helps out the video. Subscribe to the channel if you haven't already and turn on the bell if you want to be notified for future tutorials and other live streams. And if you want to support the channel, click that thanks button below or check out the patron in the description below. Y'all are the best. And I will see you guys in episode seven point two. And according to my handy dandy little plan I have created for the upload schedule. We'll be working on the by max. We'll be working on a by max system where you can either by five, 10, 100 or maximum. So you'll be able to change how much you can buy for each upgrade. So this will be pretty nice as well. So yeah, that'll be the next video. Anyways, I can't wait to make this video and I'll see you all there. Peace. Magic we born in different.