Misconception: Students often forget to include a FOREVER block around IF blocks in Scratch when programming games.

Goal:
  • Help students understand why they might need to continuously check a condition in a game, and how to do it.
Reason:
  • If a student wants code to execute as soon as an if statement is satisfied, their code must continuously be checking the if statement's condition, rather than only checking once when first executed.
Action:
  • When students report that their code isn't working, check that they have FOREVER blocks around any IF block.
  • For example, the first script below will only check if the sprite is touching the color blue once. However, the second script continues checking if the sprite touched the color blue for the duration of the program, and plays the note when it happens.
  • Top script: When green flag clicked: if (touching color blue?) then: play note (60) for (0.5) beats. Bottom script: When green flag clicked: forever: if (touching color blue?) then: play note (60) for (0.5) beats.
  • Check out Colleen’s YouTube video Forever-IF vs. IF-Forever for an explanation of how IF and FOREVER blocks interact.

More about this tip

External Source
Colleen Lewis' CS10K Scratch Webinar