Skip to content

Understanding Blocks and Scripts

In Scratch, blocks are like LEGO pieces for programming, and scripts are the towers you build by connecting them together. Each block has a special purpose, and when you combine them thoughtfully, amazing things happen!

Blocks are the building pieces of Scratch programming. Each block:

  • Represents a command - telling your sprite what to do
  • Has a specific shape - which determines how it connects to other blocks
  • Belongs to a category - indicated by its color
  • Can have inputs - white circles or rectangles where you can enter values

Understanding block shapes is crucial for creating working scripts:

🧩 Hat Blocks

Rounded tops - These start your scripts! Like “when green flag clicked” or “when space key pressed.”

📦 Stack Blocks

Rectangular with notches - These are action blocks that fit together like puzzle pieces. Most blocks are stack blocks.

🔘 Boolean Blocks

Pointed/hexagonal shape - These answer yes/no questions. Like “touching mouse pointer?” or “key space pressed?”

🟫 Reporter Blocks

Rounded rectangles - These give you information like numbers or text. Like “mouse x” or “answer.”

🏁 Cap Blocks

Flat bottoms - These end your scripts. Like “stop all” blocks that can’t have anything attached below.

Let’s build a script step by step with Vibelf’s guidance:

  1. 🎬 Start with a Hat Block Every script needs a beginning! Drag “when green flag clicked” from Events to your scripts area.

  2. ➕ Add Action Blocks Stack blocks underneath by snapping them together. The white line shows where blocks will connect.

  3. 🔧 Customize with Inputs Click on the white circles or rectangles to change numbers, select options, or type text.

  4. 🔄 Test and Adjust Run your script and see what happens. Programming is all about experimenting!

when green flag clicked
say [Hello! I'm learning Scratch!] for (2) seconds
move (50) steps
turn ↻ (90) degrees
say [Programming is fun!] for (2) seconds

Let’s explore how different block types work together:

Motion Blocks - Getting Your Sprite Moving 🔵

Section titled “Motion Blocks - Getting Your Sprite Moving 🔵”

move (10) steps - Makes your sprite walk forward
turn ↻ (15) degrees - Rotates your sprite clockwise
turn ↺ (15) degrees - Rotates your sprite counter-clockwise

💬 Speech and Thought

Make sprites communicate with speech bubbles or thought bubbles. Perfect for storytelling!

🎭 Costume Changes

Switch between different looks for your sprite. Create animations by changing costumes quickly!

✨ Visual Effects

Apply color effects, change size, or make sprites transparent. Add magic to your projects!

👁️ Visibility

Show or hide sprites, and control which layer they appear on.

Control Blocks - The Brain of Your Programs 🟤

Section titled “Control Blocks - The Brain of Your Programs 🟤”

Control blocks are like the conductor of an orchestra - they decide when and how other blocks run:

repeat (10)
move (10) steps
wait (0.1) seconds

This makes your sprite take 10 small steps with a pause between each one.

forever
if <touching (mouse-pointer ▼)?> then
say [You found me!] for (1) seconds
end

This continuously checks if the mouse is touching the sprite.

if <key (space ▼) pressed?> then
jump 50 pixels
play sound (pop ▼) until done
else
say [Press space to jump!]
end

Variables are like your sprite’s memory:

set [score ▼] to (0)
change [score ▼] by (10)
say (join [Your score is ] (score)) for (2) seconds

Use sensing blocks to respond to the user:

when this sprite clicked
ask [What's your name?] and wait
say (join [Hello ] (answer)) for (3) seconds

Use broadcast messages to make sprites work together:

// Sprite 1 (Director)
when green flag clicked
broadcast (start game ▼)
// Sprite 2 (Actor)
when I receive (start game ▼)
say [The game begins!] for (2) seconds

Here are some useful patterns you’ll use often:

when green flag clicked
forever
next costume
wait (0.2) seconds
when green flag clicked
forever
if <key (up arrow ▼) pressed?> then
move (5) steps
end
if <key (down arrow ▼) pressed?> then
move (-5) steps
end
when green flag clicked
forever
if <touching (sprite2 ▼)?> then
say [Ouch!] for (1) seconds
go to x:(0) y:(0)
end

When your script doesn’t work as expected, try these debugging strategies:

  1. 👀 Watch Your Script Run Click on individual blocks to see what each one does.

  2. 🐌 Slow It Down Add “wait (0.5) seconds” blocks to see what’s happening step by step.

  3. 💬 Add Say Blocks Use “say” blocks to display variable values and see what your program is thinking.

  4. 🔄 Test Small Pieces Run small parts of your script separately to find where problems occur.

  5. 📝 Use Comments Add yellow comment blocks to explain what each part of your script should do.

Keep your scripts neat and organized:

Put scripts that work together near each other in the scripts area.

When creating custom blocks or variables, give them clear, descriptive names.

Explain tricky parts of your code with comment blocks.

Delete scripts you’re no longer using to keep your project tidy.

Now that you understand blocks and scripts, you’re ready for bigger challenges:


Remember: Every expert programmer started with simple blocks and scripts. With Vibelf’s AI guidance and your creativity, you’re building the foundation for amazing digital creations!