Common Pitfalls and Solutions for Scratch

By Bart Huylebroeck, CoderDojo boot camp coach

Scratch won't Move?

Don't ...

If you want to move your cat to the left with the arrow keys, this is a commonly made mistake:

Sounds logical, right? If the key is pressed, move in the right direction... So why doesn't it work?

Do ...

Be sure to add a "forever" loop:

Because ...

The "if" block checks the right arrow key only once, at the very moment the green flag is clicked. What you really want, is for the script to check the arrow repeatedly. Maybe even ... "forever" ;-)

Projectiles won't Kill Enemy Sprites?

Don't ...

In a shooter game, you often work with bullet sprites that hit enemy sprites. Sometimes when they hit each other, you may see one disappear but the other survives.

Do ...

Add a pause before deleting a clone. This also gives you the opportunity to show a different costume, indicating that the projectile explodes or the enemy dies.

Because ...

Sometimes, a projectile disappears before the enemy realizes it's been hit (or vice versa). If you pause a little bit (.1 second should be plenty) before deleting the clone, that will give the other sprite the opportunity to realize it's been hit as well. Changing the costume is a bonus, but from a gameplay perspective it's important to make the game see more responsive.

Center of your sprite

Sprite not moving to where you want it to?
Maybe it's rotating around a weird spot?
That's because you have to tell Scratch where the "center" of your sprite is!
Click on the "costumes" tab so you see the drawing of your sprite.
Next, find the little grey cross in your drawing. That's where Scratch thinks the middle is.

Let's move it. Find the button in the top right with the cross on. If you click it, a giant crosshair will appear on your drawing.

Click the crosshair on a more sensible spot in your sprite. The drawing will move a little bit, but you'll notice the gray cross is now better placed. And my super-duper ninja now makes proper saltos!

Discussing Discussions...

Method 1: Pause

Pauzes are simple and work well for 2 partners, and if you keep the duration of the text bubbles constant. This might become a headache soon if you want three people talking, or if some of the text bubbles should appear for a longer time, because adding all the numbers becomes more difficult.

Method 2: Messages

Messages were designed to coordinate sprites, so they work pretty well. However, for a long conversation, you'll find yourself creating a LOT of messages.

Method 3: Variable

With a simple variable, we keep track of who's talking. Everyone politely waits until they can speak. This is a bit more complicated to set up first, but it's more scalable... and that's the magic word these days for developers :) You can add discussion partners by changing who's next to speak.

But that's a lot of blocks, isn't it?

Method 4: The Director

Of course, as in any good movie dialogue, the script can be controlled by a director. The director decides what to say and who can say it. The "director" script can be anywhere: on a single sprite or on the background. It sends a message to the correct sprite/actor. So the trigger "when I receive duckspeak" should only exist on the duck sprite, and "when I receive catspeak" should only exist on the cat sprite. Don't forget to use "broadcast ... and wait" or everybody will be interrupting each other.


There is a mistake in one of the codes? Who can find it?


  1. Damn you Maarten, for checking my code and finding a bug ;-)


Post a Comment