 Hello guys, it's Crypto Grounds here welcome back to another idle game tutorial video today We're gonna be doing OCD buy so last video we did the buy mode Button where we can switch between one five or not one five ten and a hundred and max So today we're gonna do it so around up so for 83 around up to 85 Okay, this shouldn't be too difficult So we need to hop into our upgrades manager, which is located in our earth game object Open that right up Also, if you're new here, make sure you leave a like subscribe to my channel and turn on those notifications So you can know when I publish videos almost every day and Comment your suggestions below if I have a I have a little plan here. Let me pull that up right here So what I'm doing here. I have tons of videos. I'm going to make so I'm not gonna This is just kind of what I have so far. It's like I have tons of see-tart crash course videos to do obviously because there's a lot to learn Um clicker heroes. Yeah, I'm gonna do some more clicker heroes I'm gonna do some other series like I'm gonna continue the adventure capitalist series Since I was my 500 subscriber special I feel like I should just continue that on and just keep building up and Yeah, that should be fun. Let's hop right into it. So make sure you subscribe to my channel so I can do more of those videos and It means a lot to me. You can help me grow. All right. So here we have our Our by mode right here, right? So what we're gonna do is that we're just gonna round this up, okay? And now if we can buy less then we need to just Like if we can only buy one then we're just gonna make it so only buys one or we can just make it so it just Round automatically rounds up and people love this. Okay? so we're gonna have a button here and That method is gonna be public toggle Togo OCD Okay, and this is a pretty self-explanatory. We need to open up our player data script And we need to add a so this can be considered a setting I guess so this will be public Bull and this will be OCD by OCD by Okay, we're gonna set this to false. So automatically you will not do that Okay, this is an our player data class inside the full reset method. We're setting it to false So in here, we're just gonna We're just gonna toggle that so we're gonna do game data dot OCD by is equal to itself But the opposite which is with an explanation mark just like that. So now I'll toggle between true and false and We can also manage our text here too. So let's add that real quick Okay, so we have our by mode text so we're just gonna copy and paste this and we're gonna replace it with OCD text or something like that OCD text Okay, and then in here we're just gonna Set the text equal to whatever by mode is and Let's just say what if it's true. We want OCD on And if it's not then we want OCD off and to simplify this what we can actually do is since this is the same thing We can just grab this right here and let's put the dollar sign so we can put variables in here And then in here we need print or parentheses So we'll copy this Bring this in here and replace it with just on and off Looks like that Okay, so now if it's true it'll display as on if it's false display as false Okay Now we want to load this at the beginning of the script too because it is a variable that we are saving So we need to load that text in So we should put that in our start method Cool. All right. So now what we're gonna do Is get this rounding going, okay So this is by max obviously, so we're not gonna worry about anything here but n equals five is We're just gonna change things up. Okay, so we're gonna grab an if statements if if game.data.ocd by is true Then we're gonna set n equal to Okay, so we need to let's write this down in a note document real quick. Okay So let's say our level is 83. We want to round it to 85 So we need to set n equal to two right if it's 80 And we want to get to 85 then we need to set n equal to five. Okay, so how do we do this? So we set whatever our Our level is right now Okay, so how we're gonna calculate this is we're using mod right here. Okay, so if we do 83 mod five, we get three. Okay We have three. Okay Now if we subtract that with 83 we get 80 So then all I gotta do is plus five. Okay. Okay. So now we know our steps. It looks like this It looks like this 83 or whatever our current level is minus Our current level Mod whatever the number we want to do. So for example five We add that whatever our level is again. And there we go OCD in a nutshell. So we put this in here. We need to replace some of our things, right? And obviously let's have an else And this will be n equals five. We can clean this up in a second. Okay, so Also, let's see Okay, so let's say we need to get our current level which is k Yep, so that's k k. Okay, so we do k minus k mod five plus five. All right Cool pretty simple equation. Let's see. Can we yep, we convert this to a question mark operator So now if it's true, it will be k minus k mod five plus five Well, if it's false, it'll be five. Okay, we're gonna do the exact same thing for the rest So this will be 10 plus 10 And this one also be 10 And let's just copy this here. I don't know zero and this will be 100 instead Cool. So now it'll just round up Okay, only if it can afford it So let's try this out. Oh, this is the wrong game I just was in the wrong game. How did I get that open? Um, okay Uh sink sink. I think it did Yep, it did. Okay so now We need to talk we need a button for by max because we don't have that yet So let's go to our Main screen wherever that is Oh, this is the upgrade screen. Yeah in our upgrade screen. We're gonna add our ocd button So next to the upgrade by mode, we're gonna call this the ocd button or ocd mode Whatever you'd like And we can just clean this up a bit Okay, and then we're gonna do ocd on Okay, and in our upgrade upgrades manager, we need to drag our ocd text Into the inspector and save it And we need to assign a method to this which is upgrade manager dot toggle ocd make sure you have the upgrades manager dragged in here Alrighty if you enjoyed this video so far make sure you leave a like subscribe by channel new and turn on those notifications Okay, yeah, we've been gone for five days Uh, that's a long time Okay, I want to turn off this letter notation because I don't like it Ah, I still need to fix that Let's do that real quick. Um So where is this happening? I think this is happening in our main script. Where is that right here? Okay And let's just do coins Right here. Okay. I see why is it f2? I don't remember or why is it f0? I don't remember changing it to that Weird I usually don't do that Um, oh, yeah, we got a lot of f0s. So let's just do Let's just replace all and in writer you do shift control shift f and you can see this where you can find everything Okay, so let's do f0 Um, I think this is supposed to be f2. No, it looks reasonable Okay. Well, that should fix automatically every time you load it. So now let's go to our upgrades and turn on ocd Okay, so on five our upgrade is 249. So when we can afford it, which we can't This should be able to round up, right? So let's do it to this one. So this one is uh, it costs 69 or 68. Okay um, looks like the other level texts are off. So I need to fix that too, but Oh, our level texts aren't incorrect. Yeah, aren't correct either. What's going on? Something is going on with our user interface And I guess this is something I did a long time ago and I just never noticed So that's kind of a bad thing because I'm letting people down Um, okay, let's see. Oh Click upgrade cost. Oh, this is an array Okay, so our these are That's production. Okay. So production i is equal to this text. Why is that? Okay, so it's level I see here. Okay So this is the wrong one. This should be production upgrade levels. Okay. I don't know how I didn't notice that I think that's all that was incorrect, right? Yeah, that's it. Okay. So if you ever see something like that and you see a text using the wrong thing First things first, you need to just trial and error make sure you replace variables. Check to see if it's the right one And that's my only advice because I get a lot of questions saying oh the coins text shows the cost or something like that So just make sure you're signing the wrong text or the correct text or string or whatever And the right variables because it will mix up Okay, so everything seems to be working now. Let's go to upgrades. Cool. Everything looks good Okay, so now I can buy max 173 so we can do a lot. So let's see now five. So this is all 17. So this should round up to 20 Uh, it's 22 Why is that? Okay, well, that's not good. This isn't working. What about 10? It's still buying 10. Okay. Well, that's an issue It looks like our Is our uh, I guess the only way to see this is to know if if it's even toggling Yeah, it is so it's on. Okay. So now upgrade manager. What's the issue here? So if it's true Oh, I see this is only for our click upgrade by max. So if we do this to click upgrade to Oh, okay. I see the issue here. So if we only do this to click upgrade to right here Um, let's yeah, so let's do 10 right here. It should round up to 20 Oh, it's buying more than that. It's buying out. It's actually buying 20 Okay, so that's another issue is that Okay, I see what we're doing wrong here. We're kind of getting this calculation or incorrect. So let's go back to this So let's copy and paste this calculator So let's say the level is 83 again, and we're buying five So the problem is that we are rounding it up correctly But we want this to be two because we're only buying two, right? So How do we do this? So now removing this again, we get three again, but that's not what we want Okay, so we want our actual level So then we get 80 Plus five. I feel like this is really like redundant, but It should work Minus 83 again. Okay. Now there there might be a way to simplify this big time Let's go to wolfram So wolfram alpha is good for okay. So that doesn't seem to really care. He just wants to get out Okay, it just wants to output what we get here But wolfram is very cool. I think you can do so many really cool calculations in here with really big numbers and Yeah, I give you so many answers to and it's really fast. Which is really cool Okay, so this is our equation here. So we need to just subtract it all by 83 again Because before was 85 which is correct, but we need to minus it all again by level Okay, so in here Let's put in parentheses. We need to subtract by k. Let's see. Do we need this? No, we don't Okay, so subtract by k This seems like a really weird equation, but trust me it'll work and this can probably simplified if I thought about it Because I'm just developing but I'm just making this on the top of my head right now Because that's kind of how making games works if you want to make an equation you kind of just kind of experiment with it Okay, so now it should work. So if we do 10 it should round up 20 Yay, I did it. So now if we buy say it one around up to 40 Now this is only if you can afford it, right? So we can't just do it with this one because we can't afford it Right. So now let's do 100. So now this will just round up to 100 And perfect. So let's hold by max 90. Yeah So if we can just keep doing five, so if we buy one it'll round up to five Okay, so our final test here Before we add it to production Is this five work? Yes, it does it does perfectly does 10 work Yes, it does perfectly now. I've already tested 100 Now, what about OCD? What does this do? Uh, I kind of here let me get rid of my upgrades Uh, what just one is this click upgrade to nine. Okay. So now does it work with um OCD off? Nope, it just keeps Going right it doesn't round up. But if you turn on OCD then it works Perfect work beautifully people love this and it's such an easy thing to implement It is a very very very easy thing to implement Just a simple equation right here. How many you're buying Or it's um your current level Minus the current level mod what how many how many you're buying or how much you want to round up to Plus how much you're wanting to round up to again minus the level again And that is a total of how many levels you should buy Perfect if you don't understand that make sure you kind of go back and just look at the equation So you can see how things go if you don't know what mod is here. I can explain real quick So let's do mod 30 mod 10 It's gonna be zero right because 10 divide evenly into 30 so 30 divided by three is 10 Okay, so we have no remainder. So this technically this is like the remainder. I guess we can say So if we do 31 mod 10 then we get one because mod is one is the remainder if we do clean division Right 30 divide by 31 divide by 10 we get 30 with a remainder of one. Okay So if we do 39 we get nine, right? This is really really good with um doing true or false stuff Okay, so if you want to have Something occur every 25 Okay, so let's say you have 100 you want something occur every 25 And it's true when it's zero right So if for example, this is a level. Let's say if it's 99 This is false right now because it's not zero But if we make this 100 100 mod 25 then it's zero So hopefully that makes sense if you don't make sure you do some research on that because it's very helpful Okay Now we need to copy and paste this for our production and obviously I should have just made this into a method for both But I wasn't thinking here. You know what? Let's do this. Okay And this right here we can also copy and paste this And use it for all because this is our count. So obviously the tech wasn't displaying the way we want it to be Okay So what we can do here is set n We're going to copy this method right here or this switch case right here. Okay, so now we're going to make a method um It's going to be a big double A big double obviously this should really be an int But for casting purposes for larger equations, this really gets ugly in the future So that's why it's good to cast if you have an int You want to cast n as a big double here or else it really messes things up. I don't know why happens, but it does You get infinities once your equation gets really big Past the e308 of course, even though if it's a big double it's kind of strange how it works that way But I didn't make this brick infinity. Anyways, I need to keep I need to keep going so In here, we're going to do calculate Uh by count right here Okay, we're just going to paste this in here And now what we're going to do in here is instead of n equals. We're just going to return Okay We're going to do that for all And the only thing we need in here is okay, we're going to need quite a bit. So we're going to need a big double c a big double r big double b for base costs And remember r is our cost molt. Of course, I should have done m That's probably a better one to do and c is our currency So we need k which is our levels and I should have done l for that Big double l Okay Uh, oh no big double k. Sorry Okay Okay, so this is an issue now um Okay, so this is where k needs to be an int Okay, so I'm going to cast this big double as an int to prevent issues in the future And we can get rid of this break as well because we don't need it Okay, so now for our calculate by count we do n equals by max count And we put in our stuff. So c r k b no, it's just b in k Oh, yeah, it doesn't always return something. So if it's for some reason nothing, we're just going to return zero, okay And this should be by max count or calculate by count and we can make this big double bar cool So we just now we can use this wherever we want to we can use it here So var this we can get rid of This here I think we can also get rid of this we can just return the count Okay Same thing for Where else do we have this right here? We can just return that And get rid of all this excess code And Where else do we have this? Okay, we have this right here. We can do var n equal to Calculate by count and then we have our method right here And everything should work perfectly fine. I'm going to move this above all of this Just to prevent future confusion. This is lower bicep right here Okay, so let's save that Hopefully I didn't go too fast But basically what I did is that I instead of copying pasting that same switch statement for every single by method and by count I just made it into one and we can use it wherever we want to even outside those two methods and future upgrades Okay, I'll make your code a lot cleaner So now if we do by five with ocd on it should say, okay, it's only gonna buy one Then it's gonna buy five And it's not one. So now this should work for production upgrade too. Yep See now it subtracts Now this is really cool. Look at that ocd buys king Okay Really cool how this all works together. I'm glad it does Okay, so Well, I earlier like I copy and paste all these uh calculated by counts But the b and r are actually flipped. Okay So make sure you flip all of them for every single one of them or also kind of just screw things up All right Otherwise, I think I that's that's it. Yeah, it looks like it's working now. Just fine Alrighty if you enjoyed this video and it was really helpful Make sure you smash that like button subscribe my channel if you're new and turn on those notifications because those really help me And they will help you too. The videos will help you Anyways, thank you guys for watching. Have a good day. Check out my other videos in the top of the corner See ya