It's Sean!

UK freelance journalist, author
and writer Sean McManus

Printed from www.sean.co.uk. © Sean McManus.

NEW: Sign up for my newsletter!

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.

Books by Sean McManus

Scratch Programming in Easy Steps

Scratch Programming in Easy Steps

Raspberry Pi For Dummies

Raspberry Pi For Dummies

Learn to program with the Scratch programming language, widely used in schools and colleges.

Set up your Pi, master Linux, learn Scratch and Python, and create your own electronics projects.

Earworm: a novel about the music business

Earworm

Cool Scratch Projects in Easy Steps

Cool Scratch Projects in Easy Steps

An entertaining techno-thriller that takes a slice through the music business: from the boardroom to the stage; from the studio to the record fair.

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

More books

Recommended articles

Stylised coloured photo of a synth

Discover my music and home recording articles

Interested in starting home recording? Follow me as I start recording, using instruments such as the Novation MiniNova and Korg Kaossilator, and share my synth and sample-based music online.

Scratch cat and rainbow circle

10-block demos for Scratch programming

Lots of people of all ages are learning to program with Scratch. Discover some useful tricks and techniques in my 10-block Scratch demos, including special effects you can drop into your games.

Paper Raspberry Pi case

Download free book chapters and more!

Download a free case for your Raspberry Pi, and free chapters from my books about the Raspberry Pi, Scratch, web design and more!

©Sean McManus. www.sean.co.uk.