Home > Books > Scratch Programming in Easy Steps > How to fix errors in Scratch programs

Finding and debugging the top 5 errors in Scratch programs

Sean McManus offers some top tips for finding and fixing the most common errors in Scratch

The Scratch CatWhether you program as a hobby, or are a professional programmer, you'll spend at least some of your time trying to find and fix errors in your programs (debugging). Scratch is no exception. Its use of interlocking blocks for commands eliminates a lot of typing and logic errors that you might get in other languages, but it's still easy to make programs that don't behave as you might expect.

Here are the top 5 Scratch programming errors I've come across while I've been running a Code Club:

  1. Creating variables for one sprite or all sprites when it should be the other way around. This is hard to fix. You have to delete the variable, create a new one and start over with adding the right blocks to the program. This probably accounts for a third of the errors I've seen in my Code Club, even though we remind the group often about this. It's quite a confusing concept, and it's not easy to change.
  2. Using the wrong (lookalike) block: This happens most often when somebody uses a block like [set x to 10] instead of [change x by 10]. Also common around blocks for changing variables. This probably accounts for about 20% of the bugs in my Code Club group.
  3. Putting the wrong blocks in brackets. It makes a huge difference whether a block is inside or outside a [repeat 10] block's bracket, or inside or outside an [if] block's bracket. It's particularly important to check the blocks near the end of the bracket to make sure the right blocks are inside.
  4. Putting scripts on the wrong sprite. You can copy a script to a sprite by dragging it into the right sprite in the Sprite List. Remember to delete it on the sprite where it doesn't belong, too. That last bit is the kicker that tends to cause ongoing problems.
  5. Putting blocks in the wrong order. You often have a lot of flexibility over the order that blocks go in, but sometimes it really matters. In particular, I've seen my group initialising variables (setting their starting value) after they've started using them, or inside a loop so they never seem to change.
  6. BONUS: Relatively uncommon but potentially mystifying error - Data races: This usually only happens when you're making your own programs, rather than following instructions to make other people's from books or the Code Club materials. It happens when two scripts are programmed to start at the same time, but you don't determine which will actually run first. If you're using several green flag blocks, especially on the same sprite, this might cause unpredictable behaviour. See my blog on Scratch data races for more insight.

Whether you're a Scratcher, a teacher or a Code Club volunteer, I hope that will help you to quickly find and squash the most common bugs. For more tips on using Scratch, see my books Raspberry Pi For Dummies, Scratch Programming in Easy Steps and Cool Scratch Projects in Easy Steps.


© Sean McManus. All rights reserved.

Visit www.sean.co.uk for free chapters from Sean's coding books (including Mission Python, Scratch Programming in Easy Steps and Coder Academy) and more!

Discover my latest books

Mission Python book

Mission Python

Code a space adventure game in this Python programming book published by No Starch Press.

Coder Academy book

Coder Academy

Learn to make games and other programs in Scratch, and make a web page in HTML. Highly interactive book for 7-10 year olds.

Cool Scratch Projects in Easy Steps book

Cool Scratch Projects in Easy Steps

Discover how to make 3D games, create mazes, build a drum machine, make a game with cartoon animals and more!

Walking astronaut from Mission Python book Top | Search | Help | Privacy | Access Keys | Contact me
Home | Blog | Copywriting Services | Books | Free book chapters | Articles | Photos | Games | Shop | About