Please note: This theme has not been updated to reflect Scratch 3.0. Visit this help article for more info.
Transcript

In this video, you will program a function, so you can make the android do all of the actions without repeating the same code over and over.

You could program each animation with switch costume blocks and repeat loops, but that would result in a long and difficult code stack.

Save yourself time and effort by building a function instead.

Functions allow you to reuse code stacks each time you create an animation.

You might use each animation several times in your story, so you'll make a function or a new block for each animation.

This example will make a new block for the happy animation, but you'll make a new block for each animation in the starter project you chose.

Click the make a new block button.

Name the block something appropriate for your animation.

Great, that creates a new block in the menu and a define block in the script area.

Code you add under the define block will run each time the new block is used.

To make the android animate, drag the switch costume and repeat loop code stack you already built to the define block.

Now, you can use the new block anywhere in your project to make that animation happen.

Place the new block in the story wherever it makes sense.

Try it out.

Great, the android can do this new animation in just one block now and that makes it really easy to reuse.

Now it's your turn.

Create and name one block for the first part of your android story.

Drag the code you already built into the define stack.

Then, use the new block you created, under the one flag clicked stack to make your android speak and animate.

Instructions

  1. Create and name one block for the first part of your android story.
  2. Define the new block.
  3. Use the new block to make your android speak and animate.