In this video, you will add a tune that gets louder throughout your commercial until it’sbooming. By letting the beat build, you will capture how truly inspiring it is to use yourfitness gadget.
Start by playing the music. Click on the sounds tab and select a song. Drag out a “playsound until done” block from the sound menu. Click on the dropdown, and select your favoritetune. Press the “stop” sign to stop the song. Try out a few different tunes untilyou find one you like! To ensure that your tune doesn’t ever stopplaying, from the “control” menu, place a “forever” loop around the “play sounduntil done” block. That makes your song play over and over, forever. Try it out. Ifyour song doesn’t play, make sure you’re using a “play sound until done” block,not a “play sound” block. Set the volume to start at its lowest setting.
From the “sound” menu, drag a “set volume” block into the scripts area, and set its valueto 1. This will start playing the song quietly. Click on this block stack. It will play veryquietly-- you might not be able to hear it. Click the stop sign to stop it.
Next, add volume control. The volume needs to get louder as the song plays, so it needsits own block stack. To make the song get louder over time, changethe volume by 1 forever. From the sound menu, drag out the “change volume by” block,and type 1 in the value space. Then, place a “forever” loop around it.
Try it out. Click on the “play sound until done” block stack, then the “change volume”block stack. The tune gets louder and louder, but it happens really quickly.
To change how quickly the beat reaches its loudest volume, add a “wait” block tothe code. Test it by clicking on the volume stack, then the play music stack. The musicslowly gets louder! Tinker with the wait time to slow down or speed up the volume change.
From the “events” menu, place a “broadcast” block before the “broadcast and wait”block that introduces the fitness gadget. That way, the song will play at the beginningof your commercial. Use the “broadcast” block rather than the “broadcast and wait”block - the “broadcast and wait” block will wait until the response to the messageis finished before running any more of the program, and since the response uses a “forever”loop, the rest of the program would never run!
Click on the broadcast dropdown menu and select “new message.” Type “Pump Up The Volume”as the value. Both the music and volume stacks need to receivethe “Pump Up The Volume” message. From the “events” menu, place the “when Ireceive” block above the music-playing block stack. Click the dropdown to make sure itreads “Pump Up The Volume.” Follow these same steps for the volume block stack.
Click on the flag to try it out! That sounds amazing! Before, you had to clickon each block stack separately to make the song play and get louder over time. Broadcastingthe same message to different block stacks accomplished something truly magical: parallelism– two different pieces of code ran at the same time!
Parallelism is an important concept computer scientists use every day. It means that multipleblock stacks are taking place in your program at the same time.
Here’s the game plan: Play a song using the “play sound untildone”, “forever” and “set volume” blocks.
Change the volume using the “change volume by”, “forever” and “wait” blocks.
Add “broadcast” and “when I receive message” blocks, so your code will run beforethe introduction.