If there is a wall ahead
A sprite walks into a wall and stops. Can it check first?
Step 1 of 4
- An if wall ahead block checks the way ahead.
- Wall found — the blocks inside run.
- Path clear — the blocks inside are skipped.
- The check happens each time the block runs.
Yes. An if block lets the sprite check first.
An if block runs its blocks only when the check is true.
If wall ahead looks at the square in front. A wall or the grid edge makes the check true. Then the blocks inside the if block run. If the way is clear, the blocks inside are skipped.
In the lab, the program is: Move forward. If wall ahead, Turn left. Move forward.
Switch the wall on and off. Watch the if block.
Loading lab…