In this screen cast,
you'll learn how to make a new block
and make the music selected play in your program.
First, get the music started by adding a
when flagged clicked and a play song until done block
to the stage.
In past clip sessions,
you started a project by adding blocks to your sprite,
so this is a little different.
Make sure you have the stage selected,
and try the code you've added.
(funky, upbeat music)
Your song should start playing when the flag is clicked.
There are a lot of blocks available in Scratch,
but you can also make your own block
and name it anything you want.
This screen cast will show you how to make
a grow block that will change the size of your sprite.
Add any sprite you want to your project,
then click on it to select it.
Go to My Blocks,
click make a block, and name your new block grow.
You can now select the grow block for your project
and define grow is in the script area.
If you add the grow block to your project right now,
and click on it, you will see that nothing happens.
That's because you haven't defined what the grow block does.
If you add this code to the grow block,
then click on it, what happens?
The sprite gets bigger.
You can make the grow block do whatever you want
by adding the appropriate blocks to the define stack.
You just learned one of the most important
computer science concepts.
When you made the grow block, you created a procedure.
Remember from today's first screen cast,
a procedure is a set of many instructions
packaged together to create a command.
A procedure is sort of like a shortcut.
A simple way to convey a long set of instructions
to the computer with a single action.
Procedures exist in real life too.
For example, you could tell someone to take one shoelace,
cross it over the other shoelace, tuck it under,
pull them both tight, et cetera.
Or you could just say, "tie your shoes."
Which is a shorter way that gets the same result.
Of course, if you say tie your shoes to a three year old,
they won't be able to do it because
they have not yet learned the different steps involved.
In other words, the tie your shoes procedure
has not yet been defined for the three year old.
Just like the grow block didn't do anything
before you added blocks to define it.
You have to tell the computer the instructions
for when it runs the grow block.
Procedures are important to computer scientists
because they shorten and simplify long sections of code.
For example, in this code,
you can see that it will make the sprite change color,
then grow, then change color again, then rotate,
then start all over again.
But those steps are all covered by one single procedure.
That makes it easier for multiple computer scientists
to work together on a project.
Next, you need to actually use the grow procedure
in your code, so that when the flag is clicked,
the new grow block is called over and over again
during your music video.
Add a when flagged click block, a forever loop,
and the new grow block with some wait blocks
until it is growing and shrinking at a pace you like.
Now it's your turn.
Add a sprite and click make a block
to create the new grow block.
Define the new block by adding code blocks
to make your sprite grow and shrink.
Then place a forever loop around the grow block,
so that your sprite continually shrinks and grows
when the flag is clicked.
Sign in to track your progress and earn badges