Common Programming Errors (Scratch)
This lesson will address four common errors that people often make when programming in Scratch. This will help you avoid these errors when working with the Hummingbird.
A distance sensor and a small script are shown below. This script contains an error. Find the error, and explain how you would fix it.
Using a sensor with the Hummingbird requires you to choose a threshold. If you are having a trouble with a sensor, make sure that your threshold is appropriate. For example, the distance sensor works best between 20 and 60 cm. If you have a distance threshold of 10 cm, the value of the distance sensor may never get below the threshold.
Measure a threshold for the light sensor in a bright area of the room and in a dark area of the room. What is the difference between these values? What might happen if you wrote a script with the light sensor in a dark area of the room and then ran your script in a brighter area?
What do you think will happen when you run the script below? Try it out. Was your prediction correct? How can you fix this script so that you can see the effects of all the blocks?
Many programs that use sensors involve an if then else block inside a forever loop. Such a program repeatedly executes the if then else block. The Boolean block for the if then else is checked each time the program repeats the decision. However, the Boolean block is not checked during the statements inside the top or the bottom the if then else.
Try out the script below; adjust the threshold for the light sensor if necessary. In this script, the light should turn green when the light sensor is not covered. Does the light turn green if you quickly uncover and recover sensor after the sprite turns to the right? Why? Modify this script to fix the problem.