In the next act, we introduce Mom. The letters M, O, and M are currently hidden, so let's bring them out:
The following screenshot shows the letter M as we apply the mosaic effect by 25:
The following screenshot shows the finished product after we apply the change mosaic effect by -25:
Finally, we acknowledged the Happy Birthday sprite's "hi mom" broadcast message. "Hi mom" was the cue that told Second M to enter the stage with dramatic effect.
Once the letter M is displayed, it splits apart to form a pattern of little Ms before it reconstituted itself into a whole letter. The code that created our pattern was straight forward. First, we applied a mosaic pattern with an effect of -25 each time the repeat block ran. The effect repeated 10 times. The second repeat block also ran 10 times, but it changed the mosaic effect by -25 each time. The second repeat block undid the effects of the first repeat block.
Like the forever block, the repeat block creates a loop that runs the blocks inside the loop. The repeat block differs from the forever block in that we specify a number of times to run the loop.
In addition to entering a whole number in the repeat block, we can insert variables that represent numbers. We will review variables in Chapter 6.
Programming in Scratch, like most creative endeavors, is an iterative process. That means we build our scripts one block at a time, and we can expect to make multiple versions until we get the results we want.
Our initial efforts may have a bug, which means our script doesn't perform as we expect it to. Bugs happen for any number of reasons and as we encounter a problem, we troubleshoot it. Throughout the book, we'll have many opportunities to troubleshoot our scripts, but let's focus mainly on efficiency.
Remember how, as we stepped through the exercise, we ran the clear graphic effect block to reset our sprite to its default state? In our code, we essentially cleared the graphic effect with the second repeat block because it did the opposite of what the first repeat block did.
If after we change the mosaic effect by 25 for 10 consecutive times, we add the clear graphic effect block, we create a simpler script. We get the same results, and we have less points of failure to troubleshoot in the future.
The following screenshot shows the revised script for the Second M sprite:
3.129.70.185