If you did the previous hero exercise, then you have a second ball in your project. If you didn't do the hero exercise, you'll need to finish it before you can continue:
If we were good enough, we lasted for 30 seconds and advanced to the next level in our game.
To determine when we reached level two, we did a simple arithmetic problem. We waited until the value of the timer was greater than 30 until we showed ball2. After ball2 displayed on the stage, the point in direction block set the ball's initial path to -45.
We reset the timer to 0 because the timer continually runs without any regard to the rest of the project. If we didn't reset it to 0, then our game would always start with two balls. That's not the objective.
Scratch includes three ways in which we can compare values: greater than, less than, or equal to. We can compare any combination of constant and variable values, including two variables.
When Scratch compares two values, it returns either true or false. The statement 5 = 4 returns false, while 6 < 10 returns true. Remember, when we use a variable for one of the values, the variable really contains a number.
If we compare values within a conditional statement, Scratch executes the code only if the statement is true.
If you played long enough, you might have discovered a bug in our program. Sometimes when the balls collide, the program stops running, and sometimes the balls appear to pass through each other without any problems.
Can you determine the problem? My first thought was that the X and Y coordinates of the two balls matched. The following screenshot shows a scenario where my scripts stopped running, unexpectedly. However, the coordinates of the two balls are clearly different.
What do we know about the reason our scripts stop running? We have a code associated with ball2 that says, wait until ball2 touches the color red, then stop all scripts. If you look at the previous screenshot, what color shows on the ball? The color red is displayed.
3.144.89.2