3.3 Components of Scratch: Control, Events, Motion, Operators, Variables, and Sounds
Introduction to Scratch Blocks
In Scratch, programming is done by using colorful blocks that work like puzzle pieces. Each block has a specific function, and you can join them together to create a program. These blocks are grouped in the Blocks Palette based on their functionality, making it easier for you to find the right block for what you need.
In total, there are 9 types of blocks in Scratch, and each type performs different tasks. Let’s explore these blocks and their functions.
Types of Blocks in Scratch (9 Categories)
Motion Block – Controls the movement of sprites (e.g., move, turn, glide).
Looks Block – Changes the appearance of a sprite (e.g., say, change costume, show/hide).
Sound Block – Adds sound effects, music, or voice to the project.
Events Block – Starts actions based on events (e.g., when the green flag is clicked, or key is pressed).
Control Block – Loops and conditional statements (e.g., repeat, if-else, wait).
Sensing Block – Detects inputs (e.g., mouse click, touching another sprite, loudness).
Operators Block – Performs mathematical, logical, and string operations.
Variables Block – Stores and manipulates data (e.g., score, timer).
My Blocks – Allows users to create custom blocks (user-defined functions).
1. Motion Block
The Motion Block controls the movement and position of a sprite (character) on the stage. With these blocks, you can move the sprite, make it turn, glide, or go to specific positions.
Examples of Motion Block Commands:
Move 10 steps: Moves the sprite forward.
Turn 90 degrees: Rotates the sprite clockwise by 90°.
Go to x: ___ y: ___: Places the sprite at a specific position.
Glide 1 sec to x: ___ y: ___: Makes the sprite smoothly move to a specific location.
Point in direction 90: Points the sprite towards the right.
Practical Example:
Event Block: "When green flag clicked"
Motion Block: "Turn 90 degrees"
Output: The sprite will rotate 90° when the green flag is clicked.
2. Looks Block
The Looks Block controls the visual appearance of sprites. It can change the sprite’s costume, size, color, and even make the sprite say or think something.
Example:
Change costume: Makes the sprite wear a different outfit.
Say: Makes the sprite display a speech bubble.
Example from your text:
Event Block: "When clicked"
Looks Block: "Say 'Namaste!' for 2 seconds"
Change color effect: Set color effect to 100.
Output: When the sprite is clicked, it will say "Namaste!" and change its color.
3. Sound Block
The Sound Block allows you to add sound effects, music, or even your voice to the project. You can play sounds, control the volume, and record your own sounds.
Examples of Sound Block Commands:
Play sound: Plays a pre-recorded sound (e.g., meow, clap).
Change volume: Increases, decreases, or sets the volume.
Play musical notes: Play a note using instruments.
Example:
Event Block: "When clicked"
Sound Block: "Start sound Meow"
Output: The sprite plays a "meow" sound when clicked.
4. Events Block
Event Blocks are used to trigger or start actions in Scratch. These blocks are like the "starters" of your program.
Common Uses of Event Blocks:
When green flag clicked: Starts the program when the green flag is clicked.
When key pressed: Starts the action when a specific key is pressed.
When sprite clicked: Starts the action when the sprite is clicked.
Example:
Event Block: "When this sprite clicked"
Output: When you click the sprite, it will perform the action you have programmed.
5. Control Block
The Control Block is used to manage the flow of the program. It determines when actions happen, how many times, or under what condition.
Main Features of Control Blocks:
Loops: Repeat actions multiple times (e.g., repeat, forever).
Delays: Pause the action for a specific time (e.g., wait 1 second).
Conditionals: Perform actions based on certain conditions (e.g., if-else).
Stop: Stop the script or all actions.
Example:
Event Block: "When clicked"
Control Block: "If () then … else …"
Sensing Block: "Key space pressed?"
Looks Block: "Say 'Hello!' for 2 seconds" (if space key is pressed).
Output: If the space key is pressed, the sprite says "Hello!" else it says "Namaste!"
6. Operators Block
The Operators Block performs mathematical, logical, and string operations. These blocks help you calculate, compare, and combine values.
Main Functions:
Math: Addition (+), subtraction (-), multiplication (×), and division (÷).
Comparison: Check if values are equal, greater, or less than.
Logical: AND, OR, NOT.
String operations: Combine words, find the length of a word.
Example:
Event Block: "When clicked"
Looks Block: "Say ___ for 2 seconds"
Operator Block: "10 + 10"
Output: The sprite says "20" for 2 seconds when clicked.
7. Variables Block
Variable Blocks are used to create and store data that can change during the project. For example, you can use variables to store scores, user input, or time.
Main Uses of Variables:
Set value: Set the value of a variable (e.g., set score to 0).
Change value: Increase or decrease the value of a variable (e.g., increase score by 1).
Show / hide value: Display the value on the screen.
Example:
Variable Block: "Set my variable to 0"
Sensing Block: "Ask What’s your name? and wait"
Operator Block: "Join 'Hello, ' and the user’s input."
Output: The program asks for the user’s name and replies with "Hello, [name]".
8. My Blocks
The My Blocks feature allows you to create custom blocks, also known as user-defined functions. Instead of repeating the same set of blocks, you can group them into a new block and call it whenever needed.
Main Uses of My Blocks:
Create a custom block: Group multiple blocks into one.
Simplify scripts: Make your code easier to read and maintain.
Add parameters: Create flexible blocks that accept inputs.
Example:
Create a custom block: "Greet"
Inside it: "Say Namaste! for 2 seconds."
Main script: "When green flag clicked" → Add "Greet."
Output: When the green flag is clicked, the sprite says "Namaste!" using the custom block.
Conclusion
Scratch provides a variety of blocks that help you control every aspect of your project, from motion and sounds to conditions and user input. By combining these blocks, you can create dynamic, interactive programs that respond to user actions. Whether you're building a game, animation, or interactive story, understanding these blocks and how they work together is key to becoming proficient in Scratch. Happy coding!
No comments:
Post a Comment