Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more

4. Random Lightning


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 lightning to randomly flash throughout your story. To start, place a “forever” block around the “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 the lightning strike to repeat over and over forever, and it did! Now, you just need to make the computer 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 however long 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 action is to wait 4 seconds, then it runs this “repeat” block to make the lightning strike. Once it has completed the inner loop, the computer goes back to the outer loop, waits 4 seconds, and starts again. Lightning now strikes every few seconds in your story. In nature, however, lightning doesn’t strike in a pattern. Sometimes there might be 1 second between strikes, other times the interval may 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 select a random number between the two numbers you specify. Test this, and tinker with the values. You might 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 lightning strikes 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.

arrow_backward Back
Next arrow_forward
  1. Make the lightning strikes happen forever.
  2. Put time between lightning strikes.
  3. Make the time between lightning strikes random.
Hint: If the backdrop stops on "Lightning Flash", click the "next backdrop" block, or select "Night Sky" from the backdrops tab.