In the previous video, you programmed lightning to flash. But lightning isn’t that predictable,and it doesn’t flash on command. In this video, you’ll learn how to program the lightningto randomly flash throughout your story. To start, place a “forever” block aroundthe “repeat” block. This should make the lightning repeat for the entire story.
Click the green flag to test it. Whoa! Way too much lightning.You told thelightning strike to repeat over and over forever, and it did! Now, you just need to make thecomputer wait before it runs the loop, creating breaks between lightning strikes.
Now, you’ll add a “wait” block before the repeat block. Change the value to howeverlong you want to wait between lightning strikes in your story.
Click the flag to try it again. Great!
Great! When you click the green flag, the computer enters this forever loop. Its first actionis to wait 4 seconds, then it runs this “repeat” block to make the lightning strike. Once ithas completed the inner loop, the computer goes back to the outer loop, waits 4 seconds,and starts again. Lightning now strikes every fewseconds in your story. In nature, however, lightning doesn’t strikein a pattern. Sometimes there might be 1 second between strikes, other times the intervalmay be much longer. To make your story setting more realistic,make the computer wait a random amount of time between lightning strikes.
From the operators menu, choose a “pick random” block, and place it inside the “wait” block.
Every time this block runs, it will selecta random number between the two numbers you specify. Test this, and tinker with the values. Youmight feel like a 10-second wait is too long, or that waiting 1 second is too short.
This example will use… 2 and 6 seconds. That means that lightningstrikes could occur at any interval between 2 seconds and 6 seconds.
Great! Now, it’s your turn!
1. Add a forever loop to make lightning strikes keep happening forever.
2. Add a “wait” block to wait between strikes.
3. Add a “pick random” operator to make the lightning random.
In the next video, you’ll program a story to take place within this rainy day setting.