Welcome to another fun adventure with Scratch! In this lesson, we’re going to learn how to make our own special blocks that can do different things each time we use them. These are called “custom blocks,” and they can make your Scratch projects even cooler!
Custom blocks are like magic tools that help you organize your code. You can use them to:
But what if you want your custom block to do something a little different each time? That’s where parameters come in!
Let’s say you want your character to say something different each time. Here’s how you can do it:
Now, when you use this custom block in your program, you’ll see a blank bubble where you can type in what you want your character to say. Run the code, and watch your character speak the words you entered!
Let’s try another example. Imagine you want to move your character to different places on the screen. You can create a custom block with inputs for the X and Y coordinates. This way, you can easily change where your character goes each time you use the block.
Here’s a fun idea: use a custom block to set up a math game! You can create a block that asks a math question using two numbers you provide. The program can then check if the answer is right and respond accordingly.
You can even use multiple custom blocks together or put one custom block inside another. The possibilities are endless, and you can create amazing projects with these tools. Don’t forget to check out other “My Blocks” videos for more tips and tricks.
Now it’s your turn! What awesome things will you create with custom blocks in Scratch?
Start by creating a custom block in Scratch. Think of a simple task you want your character to perform, like saying a greeting. Use the “Make a Block” feature and add a parameter to change the greeting each time. Experiment with different phrases and see how your block works!
Use custom blocks to design a mini game. Create a block that moves your character to random positions on the screen. Add parameters for speed and direction. Challenge yourself to make the game more interesting by adding obstacles or goals!
Write a short story using custom blocks. Create blocks for different scenes or actions in your story. Use parameters to change the dialogue or actions in each scene. Share your story with classmates and see how they use custom blocks in their stories!
Develop a math quiz using custom blocks. Create a block that asks a math question with two numbers as parameters. Program it to check the answer and give feedback. Test your quiz with friends and see who can get the most correct answers!
Work with a partner to create a collaborative Scratch project. Each of you can create custom blocks for different parts of the project. Combine your blocks to make a fun and interactive program. Present your project to the class and explain how you used custom blocks!
Here’s a sanitized version of the provided YouTube transcript:
—
In previous videos on Scratch My Blocks, we’ve explored creating a custom block, tips and tricks for success, and when and why you might want to use them. The My Blocks category of blocks may be used to protect a sequence of code that has been proven to work, collect a sequence of code that will be used repeatedly, or to parse out sections of code for easier assembly elsewhere.
However, the blocks we’ve created so far perform the exact same steps each time. What if we want to execute the same procedure each time the custom block is called in the main program, but with small changes, like the text shown, the coordinates used, or adjusting the value in one or more of these blocks? Let’s learn how to create a My Block that can be customized each time it is used.
Let’s start by setting up a custom block that has the character speak and say certain text simultaneously. You’ll see the code stack I want to use here. I’ll click “Make a Block” and give it a descriptive name, like “speak and say.” Since I want to customize the text my sprite will speak and say each time, I’m also going to add an input. With an input in place, the custom block will use the parameter (the data I provide) in the input bubble when I use the block. In this case, the input I’m choosing is “number or text.” To remember what the input is, I’ll give it a descriptive name, like “what to say.”
Back in my scripts area, I’ll add the desired code sequence under the “define” block. Then, in place of static text in the “speak” and “say” blocks, I’ll use the input I created while making my block. To get the input, click on the input label in the “define” block and drag it to place it in a code block. I want to use the same text in both the “speak” and “say” blocks, so I’ll do that twice.
Now, when I use this custom block in my main program, you can see the blank input bubble where I can enter the parameter, in this case, my custom text. Let’s run the code to see how it looks. “Hi! I’m a dragon. I have hot breath.” I’m able to use the same code sequence and customize it repeatedly without rewriting this code stack each time. If I need to make edits to the procedure, I only need to make changes under the “define” block to update everywhere the block is used in my main program.
Let’s see another example where I want to customize the X and Y coordinates every time I run my custom block. As I create my custom block, I can add labels between inputs to help me remember what is what as I use the block and fill in the parameters.
Here’s one more example where I’m using a custom block to help me set up a math game. In this case, I’m providing the two numbers in my question each time I use the custom block. The program uses those parameters in my custom block to ask the question, check the user’s answer, and provide the appropriate response.
I can even set up multiple custom blocks with or without inputs and use them together, or add a custom block inside another custom block. Be sure to check out the tips and tricks shared in the other “My Blocks” videos for more information. The possibilities are endless. What will you create?
—
This version maintains the instructional content while ensuring clarity and coherence.
Scratch – A visual programming language that lets you create games and animations by snapping together code blocks. – Example sentence: In Scratch, you can make a cat dance by arranging the blocks in the right order.
Blocks – Pieces of code in Scratch that you can snap together to create a program. – Example sentence: To make the sprite move, you need to use the motion blocks in Scratch.
Code – A set of instructions written in a programming language that a computer can understand and execute. – Example sentence: When you write code, you are telling the computer what to do step by step.
Custom – Something that is made or modified to fit a particular need or requirement. – Example sentence: You can create a custom sprite in Scratch to make your project unique.
Parameters – Values or settings that you can change to affect how a program or function behaves. – Example sentence: By adjusting the parameters, you can change how fast the sprite moves across the screen.
Input – Information or data that is entered into a computer or program for processing. – Example sentence: The program asks for your name as an input to greet you personally.
Character – A symbol or letter that can be used in text or programming. – Example sentence: Each character you type on the keyboard is stored as data in the computer.
Say – A command in Scratch that makes a sprite display a speech bubble with text. – Example sentence: You can use the “say” block to make the sprite introduce itself to the audience.
Program – A complete set of instructions that a computer follows to perform a task. – Example sentence: We wrote a program in Scratch that makes the sprite jump when you press the spacebar.
Coordinates – Numbers that determine the position of a point on a grid or screen, usually defined by x and y values. – Example sentence: In Scratch, you can use coordinates to place your sprite exactly where you want it on the stage.
Cookie | Duration | Description |
---|---|---|
cookielawinfo-checkbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics". |
cookielawinfo-checkbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". |
cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". |
cookielawinfo-checkbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other. |
cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance". |
viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |