Professional Documents
Culture Documents
Semester 2 – Week 9
Debugging Scripts using Scratch
Source: http://wiki.scratch.mit.edu/wiki/
Scratch Debugging
• A common problem for Scratchers is when a script that may seem to be flawless ends up
not doing what is expected, or getting highlighted in red. These are usually normal human
errors and can be fixed.
• For example, to find the sum of the fractions 1/2+1/3+1/4+…+1/100 one may use the
following script:
• Leave comments wherever you had to spend time to get something to work right; this
way, if it breaks again, you can refer back to what worked before. Anyone with enough
experience should be able to understand your script at first glance.
• Do not blindly copy scripts from other projects, unless that was the intention of the
project. Other than moral copy theft issues, chances are the script will not work in the
context of your program.
Checking Values
• If a value needs to be known in order to determine whether or not a script is
functioning, there are a few ways to find it, such as:
• Often, the best way is to simply run the project again and again.
• However, large games or animations would be painful to debug like this. Instead, you
can introduce certain testing codes, which can be removed in the final release. For
example, to test level 27 of a game, add a script where when "space" is pressed, the
game goes to the next level.
Single Stepping Debugging
• Single Stepping Debugging is a feature that was available on Scratch 1.4 and is no longer
available on Scratch 3.0.
• Normal: Just runs all the scripts as they would normally be; it's just like having Single
Stepping turned off.
• Flash Blocks (fast): Runs a project at normal speed, however, when a block is active, it
turns yellow. This is useful for debugging.
• Flash Blocks (slow): Runs a project extremely slowly, and turns blocks yellow when they
are active.
Uses for Single Stepping Debugging
• Single Stepping Debugging can be useful for: