 Hello, well, it's the surfing scratcher here bringing you another video connecting the world of maths to scratch You have already checked the description below for links to previous videos as this one's part of a series Also got the project down there so you can remix it ready to create your mathematical rule In this video, we're gonna take our mathematical rule that we looked at in the last one in our scratch planner and translate it into scratch blocks I've got some comments throughout the project that we're gonna step our way through Feel free to just read those comments and watching this video. Let's get stuck into it. Hey here We are back in our scratch project where we're now going to code the rule that we created in the last video So I'm in the custom rule sprite and we are now going to walk through each of these individual steps Anything that's changed. I've actually just put in step one here So they refer to other comments in this sprite step one define the rule to do that creating new variable with the name of The rule in your defined rules block. Okay, so in step one, that's this part down here step one figure You want to make so we know what we want to make we did that in last video a rule between 20 and 30 Give it the name rule underscore rule name where rule name is the name of your rule great Make sure the variable is to this right only so let's go across into our variables and let's make that variable for this sprite only rule underscore between 20 and 30 Cool that part is really super simple it pops up here and the reason for that is we just need to hide it So if we uncheck that box, it goes away Now we need to make sure the variable is to this right only and we need to set it in here So in our define rules block so you could go into your variables and find the set block and a simple way to do that is just duplicate this one and Find the rule that you just created rule between 20 and 30 wonderful the text that you're going to write there is the text that Displays when you click a sign. So the text that we want in there is between 20 and 30 so that is now Our variable. Let's find the next thing we have to do need to add the rule So grab an ad block from the list category and add your variable to the list custom rules So I'm actually just going to go across and find our step two So grab an ad block from the list or just reconnect that one there. So that is our rule greater than 10 We need to grab another ad block. So if you're in the variables Into the list section of it, you can go you can add a thing now We want to add our rule to our custom rules here So let's do that and go back to our variables and find that rule that we just created rule between 20 and 30 And we now need to add it. So if I just pop that at the top and I just connect it I'm now only adding the rule between 20 and 30. I'm just forgetting this rule up here So let's go back to our step three with what we need to do We need to create the rule block So make a custom block that checks whether or not the rule has been met So somewhere down here is a step three. Here it is So step three in the my blocks category, which is this one just here Create a custom block name the block with a question mark at the end of it as this shows We are checking something. It'll be either yes or true So let's do that Let's make that custom block and if we jump back over to our plan We said that we were going to call that is between 20 and 30. So let's actually do that is between 20 and 30 I like to put the question mark there because we're kind of asking questions like that inflation is between 20 and 30 I don't know. Yes or no. So click okay there. And now we have got our custom Block defined there, but there's nothing in it. So we need to do something We need to create the condition for when the rule is met. I can't tell you what that is Well, I can in this video, but when you create your own ones, I can't tell you what that will be So let's go ahead and create the conditions for that. So if we jump back across into Sketchbook, we can see that if the answer is between 20 and 30 then pop up them all so the very first thing that we need to do is grab this if block right there and You can see that we've sort of got something very similar to what we need in this greater than 10 blocks So I'm just going to go ahead and duplicate that We'll just go through the stuff that we need. So if our answer is greater than 10 Well, we actually want this one to be greater than 10 But we want it to be greater than 19 because remember our rules for between 20 and 30 and for our purposes This is including 20 and 30. So if our answer is greater than 19 that includes all the values 20 and above but we need to stop that before it gets to 31 so we need this and Something else. So we're going to go into our operator category. We're going to get an and block And then we're going to get a less than block. So what we need to do here is we need to get our answer and Check that it is less than 31. So if it's less than 31 then it's going to be 30 29 28 27 26 So on so forth the last thing I need to do is just slot This block inside that and and we smush them together So if our answer is greater than 19 and our answer is less than 31 then we're between 20 and 30 So that is working the exact way it should So when the condition is true call the notify rule to animate. So just by duplicating this last Block here of code. We already got that for free if you wanted to do that manually You go into my blocks and you would go get the notify rule to animate one just there But pretty easy just to duplicate it. We don't want to check The rule greater than 10 anymore that variable So we're going to go get rid of that and we need to go get the rule that we just created which is the rule between 20 and 30 So this is just the custom block that I created That basically matches the guest rules that a user has guessed with the currently active rules in the game So you don't need to worry about that one. Your focus is just on the mathematical component of this game Cool. So we've done step three. Let's check out. I know there are four steps in here So what is the fourth step that we need to do? We need to now call the block We need to add the custom block you just created to the validate user answer and then we're done So let's scroll down to where step four is there it is call your custom block inside the statement So right now we're calling if it's greater than 10 Now what we need to do is also add that custom block that we just created. So are you now between 20 and 30 So actually see if our block works what we need to do now is start the game So I just press the green flag and I can a little cheat here is if I Check active rules and I can see the four rules of the moles that are here. So rule One so the the yellow moles rule is an odd number Our green moles rule is less than 20 our Purple pinky purple moles rule is a three digit number and our blue mole is between 20 and 30 if I expand that out So what we need to do now is we need to click the chick to enter a number and now let's enter the number 20 Cool, and there goes our blue mole just as you would expect. Let's enter in the number 19 now Cool and our mole does not pop up if I enter in the number 31 I'd expect it to not pop up and it doesn't now. Let's enter in the number 30 Cool, there goes our mole again. So that's working just dandy The last thing we need to do is just to check if this actually works. So our rule four is that between 20 and 30 Enter number one Boom, there we go and our sign turn to green. So we're done. You can make rules until your heart's content I would definitely encourage you To work in the scratch planner before you jump into this project just to help spell out your ideas I find that is super super useful That's it for this video, and that's it for our series on whack a rule I hope you enjoyed it did give it a thumbs up and make sure you hit that subscribe button and the bell So you'll notified when more videos are released in the future. You can check out links to my other projects They should be popping up right now and Also, drop me a comment to post your remix project and show me your mathematical rule I'm also really interested to hear about what you want to know in scratch So then I can make some bite-sized videos for you, but until then I'm off to go find a way. Take it easy