To make code easier to read, computer scientists
use something called functions.
These are reusable blocks of code that do one task.
In scratch, you can also define your own function.
For this add-on, you will create a function that moves
the narrator's mouth while it says things.
To create your own function block, click on, "more blocks,"
then click, "make a block."
This block will make the narrator talk,
so name it something that makes sense, like talk.
A large block with an arc at the top that says,
"define talk," will appear in your scripts area and
a block called talk will appear among the blocks you can
choose from now.
Click on the talk block.
Okay, right now it does nothing.
That's because talk hasn't been defined.
The first time you see a new word, you probably look up
its definition in a dictionary.
The define block works just like a dictionary.
It is where the program goes to look up the meaning of
"talk," and find out what it should instruct
the computer to do.
Now, place the code that makes the narrator talk
underneath the define block.
Then click on the talk block again.
Now the narrator's mouth looks like it's moving
while he talks, just like it did when you ran the code
without the function.
But wait a minute, the point of a function is that you can
Right now, the function only makes
the narrator say one thing.
This main character's name is Dino.
In order to use the function you created in more than
one spot in the program, you need to make it tell
the narrators to say the different words and phrases
you created in part one.
Luckily, functions can receive input, which is kind of like,
special instructions you give to the function
to make it do what you want.
Input will allow this function to say whatever gets sent
to it, rather than just repeating,
this main character's name is Dino.
To give the function input, right-click on
the block definition, then click Edit.
An edit block menu of possible inputs you can add to
your block appears.
In code, words and sentences are called strings.
So click, add input.
This adds a block next to the name of the function up top.
Try naming the input something that describes how it's used,
like, narrator's words, then click okay.
The talk block now has a space next to it,
which is where you'll put the words you want
the narrators to say.
You can either cut and paste or re-type
the narrator's dialogue into the talk block.
Now, you're sending this main character's name as Dino
as input to the talking function.
Next, the program needs to know how to use the input.
Click on narrator's words in the definition and drag it into
the first save block.
Click on the talk block to see this work.
The narrator says, "This main character's name is Dino,"
while it's mouth moves.
Now, drag out another talk block.
This time, write the next line of the narrator's dialogue
for your story.
In this example, the next line is, "He is friendly
and likes to dance."
Click on the two talk blocks, the narrator says,
"This main character's name is Dino."
Then, "He is friendly and likes to dance."
Great. You can send any string input
to the talking function.
The narrator will say whatever you input
while moving it's mouth.
Finally, replace all the save for two seconds blocks in
your code with talk blocks.
Now it's your turn.
Create a new block by going to the more blocks menu,
clicking make a block and naming it something that
Place the blocks stack you made in the last screencast,
under the defined block.
Edit the block to take string input.
Edit the say block to "say" the input.
Use the new block instead of the save for two seconds block
in your story.
In this add-on, you will change your story’s setting.
Animate a mystery box to appear!
Animate the narrator to talk!
This add-on will show you how to use Scratch to create your own song.
In this add-on, you add another character to your story to spice it up!
Sign in to track your progress and earn badges