Chapter 12: My Blocks (Custom Functions & Parameters)
Break large scripts into named, reusable building blocks with custom inputs.
Lesson goal & core concept
Reduce duplicate code and use "Run without screen refresh" safely for instant drawing or collision resolution.
When a custom block is called, Scratch runs its definition from top to bottom and returns right back to the caller.
Step-by-step practice
Work through these steps in the Scratch editor, predicting each result before clicking the green flag.
- Identify repeated code (like drawing a shape or resetting the player).
- Create a My Block with clear parameter names (e.g., sides, size).
- Call the same block multiple times with different numbers.
- Keep "wait" blocks out of "Run without screen refresh" definitions.
- Define (Draw Polygon sides size)
- Repeat sides
- Move size steps
- Turn clockwise (360 / sides) degrees
Try it: Draws triangles, squares, or octagons with one clean custom block.
Mini challenge & next steps
Call Draw Polygon three times in a row with different sizes to create nested geometric art.
FAQ
How long should I spend on "Chapter 12: My Blocks (Custom Functions & Parameters)"?
Aim for 15–20 minutes: read the concept, test the small example, modify one value to see what changes, and try the mini challenge.
This guide is provided for educational purposes. Scratch screens and terms may change over time, so please check the official Scratch website as well.