Your First Scratch Program: Make a Sprite Move and Talk
Kids open Scratch, tour the editor and snap blocks together to make a sprite say hello and walk back and forth with a forever loop.
CarnielSeriesCoding for Children3 of 4
On this page15 sections
Hello again, coder! So far you have learned that code is a set of instructions, that a sequence is steps in order, and that a loop repeats steps so you don't have to write them again and again.
You did all of that with paper. Today you will use a real computer and write your very first program. Let's go!
Meet Scratch
Scratch is a free coding tool made for kids. Instead of typing code, you snap colorful blocks together, like puzzle pieces. Each block is one instruction. Millions of kids around the world use it to make games, stories and animations.
To start, you need a computer or tablet with an internet browser. Then:
- Go to scratch.mit.edu.
- Click Create at the top of the page.
That's it! The Scratch editor opens, and it is ready for your code.
A Quick Tour of the Editor
The editor has five main parts. Find each number in the picture, then find the same part on your screen.
- Block palette: all the blocks live here. The colored circles on the far left are groups. Blue Motion blocks make things move. Purple Looks blocks make things talk and change. Yellow Events blocks start your code. Orange Control blocks hold loops.
- Code area: the big empty space in the middle. Drag blocks here and snap them together.
- Stage: this is where your program runs. It's like a little theater.
- Sprites: a sprite is a character or object on the stage. Scratch gives you a cat sprite to start with. In our pictures we use a robot, but your sprite will be the cat.
- Green flag and stop sign: click the green flag to start your program. Click the red stop sign to stop it.
Build Your First Program
Here is the program you are going to build. It makes your sprite say hello, then walk back and forth across the stage, forever.
Follow these steps. Each block snaps under the one before it. You will feel it click into place.
Step 1: Start with the green flag
Click the yellow Events circle. Drag the when green flag clicked block into the code area. This block goes at the top. It means "start here when someone clicks the green flag."
Step 2: Say hello
Click the purple Looks circle. Drag the say Hello! for 2 seconds block and snap it under the green flag block. Click the word Hello! inside the block and type: Hi! I'm learning to code!
Step 3: Stay right side up
Click the blue Motion circle. Scroll down to find set rotation style left-right and snap it under the say block. Without this block, your sprite would flip upside down when it turns around. Try it without the block later and see!
Step 4: Add a forever loop
Click the orange Control circle. Drag the forever block and snap it at the bottom of your stack. A forever block is a loop that never stops (until you click the stop sign). It has a gap inside, like a mouth. The blocks you put in the gap will repeat.
Step 5: Fill the loop
Put these four blocks inside the forever loop, in this order:
- move 10 steps (blue Motion)
- if on edge, bounce (blue Motion)
- next costume (purple Looks)
- wait 1 seconds (orange Control). Click the 1 and change it to
0.1.
Check your stack against the picture. Every block should be snapped together, with no gaps.
Press Play!
Click the green flag. Your sprite says "Hi! I'm learning to code!" for 2 seconds. Then it starts walking. When it reaches the edge of the stage, it bounces and walks the other way. Back and forth, forever!
Did you notice the legs moving? That's the next costume block. A sprite can have a few pictures, called costumes. Switching between them quickly makes it look like the sprite is walking, just like a flip book.
Click the red stop sign when you're ready to stop.
Something not working? That's a bug, and you know what to do. Check that every block is snapped in, that the four loop blocks are inside the forever block, and that the green flag block is at the very top.
Challenges
Real coders change their code to see what happens. Try these one at a time, then click the green flag to test:
- Go faster: change move 10 steps to move 20 steps. What about 2 steps?
- Change the message: make your sprite say your name, or a joke.
- Add a sound: click the pink Sound circle and put a start sound block inside the loop. (Tip: it gets noisy fast!)
- Stop after a while: take the four blocks out of the forever loop, swap the forever block for a repeat 10 block from Control, and put the four blocks back inside. How is it different?
Saving Your Work
There are two ways to keep your project:
- Save to your computer: click File, then Save to your computer. Next time, use File, then Load from your computer to open it again.
- Make a Scratch account: with an account, your projects save online. Click Join Scratch at the top of the page. If you are under 16, Scratch asks for a parent or guardian's email, so ask a grown-up to help.
New Words
- Scratch: a free tool for coding with blocks.
- Block: one instruction in Scratch.
- Sprite: a character or object that your code controls.
- Stage: the area where your program runs.
- Costume: one of the pictures a sprite can show.
- Program: a set of code that does a job.
Quick Quiz
- Which block makes your program start?
- Your sprite flips upside down when it turns around. Which block fixes that?
- What is the difference between a forever block and a repeat 10 block?
- How do you make a sprite look like it is walking?
Answers: 1. When green flag clicked. 2. Set rotation style left-right. 3. Forever keeps going until you click stop. Repeat 10 does the steps 10 times and then stops. 4. Use next costume to switch between its pictures quickly.
What's Next?
You wrote a real program. Amazing! Right now your sprite does the same thing no matter what. Next time, you will learn about events and if-then, so your sprite can react when you press a key or click on it. Your programs are about to get a lot more fun.
For Grown-Ups
Scratch is free and made by a team at MIT, and it runs in any modern browser. No account is needed to follow this episode. If your child wants to save projects online, Scratch asks for a parent or guardian's email for anyone under 16. Until that email is confirmed, kids can still build and save projects, but they can't share or comment. If a block won't snap, the most common cause is dropping it slightly off to the side. Let your child find and fix the problem first. That debugging moment is where much of the learning happens.