Goal: The cars will stop after one car runs 30 laps.
Vocabulary: if, bk (back), announce
We need to add more instructions to the yellow and red colors. It will be easier if we write a procedure for each color. We'll call these procedures redcar
- Change the red instruction to just one word: redcar.
- Change the yellow instruction to just one word: yellowcar.
Now when a car passes over its color, it will follow that procedure.
- In the redcar and yellowcar procedures, instead of wait random 50, change the command to
wait 10 + random 40.
This way we are sure that each car will disappear for at least one second before reappearing. It may still disappear for up to five seconds.
- If red_lap = 30 means, "If the number in the red_lap text box is 30, do what is in the next set of brackets. If it is not 30, ignore what is in the brackets." So the car will keep racing until the text box reaches 30.
- The first command inside the brackets is bk 50. That moves the car back a bit so that it appears to be at the finish line instead of the starting line.
- Announce opens an alert box containing the message inside the brackets." It will tell us which car wins. Click OK to make the announcement go away.
- Stopall makes sure that both cars stop running, since the race is over when one car completes 30 laps.
- The yellowcar procedure works the same way for the yellow car, every time it passes the yellow starting line.
Try writing different announcements for the finish of the race.
Can you add a third car into the race? Remember to program the car, add another racing lane, and give the lane a starting line with a programmed color.
On Your Own - Project Ideas
Can you make something else happen when the race is over?
(Maybe you can record the sound of a crowd cheering after the announcement.)