 Scratch Blocks, what are they and how do you use them? Well get those hands nice and warm because in this tutorial of Scratchery Basics I'm going to explain all the types of blocks in Scratch Programming through a demo that we'll code together in just a moment. Hello world it's the surfing scratcher here, teacher, surfer, programmer and lover of learning bringing you the goodness of learning through code. On this channel we code projects together using video tutorials so if you're new around here consider hitting that subscribe button. Be sure to check out the show notes and links in the description below as I list out a bunch of resources and unplugged activities that can help you along on your learning journey. Alright let's get stuck into it. Alright so you may press that create button but I recommend you grab a copy of this starter project for this tutorial. You can find a link to it in the description below so go and click on that first. Okay let's talk about Scratch Blocks. Scratch Blocks can be found under the code tab and they live in this column just here. I want you to be thinking about a jigsaw puzzle that you may have done. So jigsaw puzzles have those center pieces and they have pieces that go around the edges. We're going to be talking a little bit about Scratch Blocks with that sort of metaphor of jigsaw pieces. Let's move on to the first type of blocks in Scratch. Ad blocks. Ad blocks start a script or a block sequence and they've also got these bottom bumps that you can connect other blocks to. They're mostly found in the events category. You can also find them in your custom blocks and extensions. Let's go use our first one. We're going to click on the cast sprite. Head over to events and drag out when the green flag is clicked. Okay let's look at the next type of block. Stack blocks. So stack blocks are like the middle pieces of our jigsaw puzzle. You'll see they've got a top notch that you can connect to other blocks which are above it. They've also got a bottom bump which you can connect other blocks beneath it. Stack blocks tell the sprite what to do. They are the main commands or instructions. Here I've listed out just a few from all the various categories. They're found pretty much everywhere. Let's go connect our first stack blocks. Going to jump over to the car. Head over to the motion. So when the green flag is pressed we want the car in this position. So let's go ahead and grab the stack block for it. Go to the current X and the current Y value. We also want to point it in the current direction that it's in. So let's go get that stack block. See how I've just connected them both and we're going to change that to zero which reflects the current direction. You'll see that as I move my car over here and I press the green flag it now goes directly back to the starting line. Okay so we want our car to go around the track. To do that we're going to use a block that will animate our car from this position up to a new position here. Let's just move our car. So we want to move it through code. The block that we can use to do that is a glide block. A glide block just animates a sprite for us. So over one second it's going to glide to this new position. So let's press the green flag and see what happens. There we go. So after the car has hit this position we want to change the direction that it's in. So we want to point it west. Let's go get our point block and change it. Okay now if I press the green flag we'll have gone to the start and now our car is oriented. What I want you to do now is repeat what we've just done but for every straight and every turn around the track until we get back to the start. I'm going to do it and I'm going to speed it up for you. But follow along with me. Okay so now if we just go ahead and click the top of this we'll see our car animate around the track. And it's pointing in all the directions that we would expect it to do and it'll head all the way back to that starting point. Head on over to the events and just grab out another when the green flag is clicked block so we can start to talk about our next type of block. C blocks these kind of look a little bit like a burger or a sandwich where you can stick other blocks inside of. We use them to loop things and to check conditions. I'll show you an example of what I mean. Let's get into the costumes of the car. You'll see here that we've got two costumes. We've got a blue costume and a pink costume that we can alternate between. We can change the color of our car depending on the direction that it is pointing. So let's code that. Head back over to the code of the car. We're going to go over to the control category and grab out an if statement. And what we're essentially going to say is if our car is pointing in a direction then we want to set it to the blue car. And if our car is pointing in the other direction, set it to the pink car. We'll put that specific information in this hexagonal shape here, which is a nice segue to our next block type. Boolean blocks. They have this hexagonal shape and they fit inside other blocks. Now a Boolean block just means that something is either true or false and that can be represented by a zero for false and a one for true. So what we're going to do is we're going to check the direction of our car sprite. Let's do that. Jump over to the car. Now head over to the operators. Grab out a greater than Boolean block. And we're now interested in another type of block. Reporter blocks. These are rounded rectangles. They fit inside other blocks as well. And they give us a value about the sprite. Sort of property or attribute or a feature of the sprite and its value. So you remember that we were just interested in the sprite's direction. So what this block does is it tells us a direct reading of this value here. So currently our block info is selected. If I were to click this, it should come up as 90 and it does. It's just telling us what this value is equal to. So we're going to use this direction block for our car. Jump back over to the car. Head on over to your motion. And scroll down until you see these three reporter blocks here. Exposition, Y-position, and direction. Grab out direction. If you click direction, it will say 90. That is the direction the car is pointed in. We're going to get this block and put it inside that Boolean block. I'm going to say if the direction is greater than, well, let's go zero. If the direction is greater than zero, let's show our blue car. So if our direction is greater than zero, let's switch to our blue car costume. Head on over to your looks. We want to switch to costume here and we want to switch to the blue costume. Cool. Now we can go ahead and duplicate this block by right clicking. Bring it down there. We need to go back into our operators and get a less than Boolean block here. Let's make that zero. I'll duplicate the direction once more. Place it into the Boolean block. I'm going to get rid of this by just dragging it onto the blocks. Now let's put that new Boolean block inside that hexagonal shape there. Cool. Now we want to change this costume to pink. We can connect those up and we can connect it on a green flag press here. So let's press the green flag and boom, our car is blue. But it's not doing anything. And the reason for that is it only does it on the green flag press. So we need to fix that. That's a good time to talk about our last type of block, cap blocks. All right. So these have a top notch so that you can connect it to other blocks above it. But it has a flat base, which means this is the end of the road. Nothing can be connected to the bottom of it. And these blocks stop a block or a script from running. So you do this right at the very end. You notice over here that these are our two cap blocks. And I've put in this forever C block in here as well because it also has a flat base. And this is going to be the one that we're using, but it's not actually a cap block. It's still a C. Encourage you whenever you see drop down menus like this to click on them and have an explore of what you think they might do. Let's jump back over to our car. We're going to need that forever block. Let's go into our control blocks and grab out a forever block. Now, what you can do is if you drag your forever block to the top of that cap block there, that will just place all those other C blocks inside that forever block. Now, if we press the green flag here, we should see our car change from blue to pink and then back to blue. There's also a quicker way that we could have done this. If you scroll back over to your control category here with all the control blocks, if you get an if else statement, we can just put in one condition there. So if the direction is greater than zero, we can switch the costume to blue. Otherwise, just make it pink. So we can actually just simplify our code a little bit there. I think we should do a few laps of this racetrack. So let's go out and grab a repeat C block. And I like the number three. Going around three times seems pretty cool. Let's get that C block and let's place it just beneath those two stack blocks where we start the project. So when we go to that first position and we point in the direction, then we want to go around the track. That's all these instructions here. The final thing that we're going to do now is we're going to go back into our control blocks here. And we're just going to get one of those cap blocks that finally stops all the scripts running in our project. So we've covered all the types of scratch blocks. And in the future video, we'll talk about all the types of categories of scratch blocks as well. All right, it's time for a scratchy question. Are you still a little bit fuzzy on some of the scratch block types? It's totally cool. You're learning. Comment below on your fuzziness. And I'll point you on some more stuff that can help you out. Hey, thanks for checking out this tutorial. Subscribing the bell if you're new around here. And be sure to have a scout of my other content, which is on the screen right now. If you can't get enough, then head on over to my Patreon page where you can join a membership tier for access to exclusive content. Link in the description below. But until then, I'm off to go find a wave. I'll catch you in the next one.