Free learning tools for curious minds, families & classrooms
the curiosi
AI Quiz Maker

LEARN · PRACTISE · DISCOVER

Events: Making Things Happen

Read at your own pace. Try the practice, then continue your course.

In real life, things happen because of events. When the school bell rings, the class goes out to play. When you press a doorbell, it rings. In Scratch, event blocks start scripts when something happens. In this lesson you will use events to control your sprites with the keyboard and mouse.

Hat blocks

Event blocks have a rounded top, so they are called hat blocks. A hat block always sits at the top of a script. Nothing can go above it.

Event blockThe script runs when…
when green flag clickedthe green flag is clicked
when (space) key presseda chosen key is pressed
when this sprite clickedsomeone clicks the sprite
when backdrop switches to (backdrop1)the backdrop changes

Controlling a sprite with arrow keys

Let’s make a sprite move with the arrow keys. You need four small scripts, one for each arrow.

when (right arrow) key pressed
change x by (10)

when (left arrow) key pressed
change x by (-10)

when (up arrow) key pressed
change y by (10)

when (down arrow) key pressed
change y by (-10)

Click the stage first, then press the arrow keys. Your sprite moves around!

Facing the right way

To make the sprite face the way it moves, add point in direction (90) to the right-arrow script and point in direction (-90) to the left-arrow script. If the sprite turns upside down, click the sprite’s Direction setting and choose left/right rotation style.

Clicking on sprites

when this sprite clicked is great for buttons and surprises.

Example

Leo made a drum kit. He added a Drum sprite with this script:

when this sprite clicked
start sound (High Tom)
change size by (10)
wait (0.2) seconds
change size by (-10)

Each time he clicked the drum, it played a sound and “bounced”. He added a cymbal sprite too, and soon he had a whole band!

Many scripts at once

A sprite can have many scripts, each with its own hat block. They can run at the same time. One script might control movement with the arrow keys, while another plays music when the green flag is clicked. This is called parallel programming, and it is how games handle lots of things at once.

Common bug: keys do nothing

If pressing keys does nothing, click once on the stage first. The browser only sends key presses to Scratch when the stage is selected. Also check that each script has the right key chosen in its drop-down menu.

Key takeaways

Practice

Make a sprite that says “Ouch!” when it is clicked, and jumps up 50 and back down when you press the space key.

Answer: script 1 is when this sprite clicked, say (Ouch!) for (1) seconds. Script 2 is when (space) key pressed, change y by (50), wait (0.3) seconds, change y by (-50).

Share this
error: Content is protected !!