Skip to content

Please update your browser

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

3. Android Actions

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 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 More Blocks menu, then 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 Scripts 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 when flag clicked stack to make your android speak and animate.

arrow_backward Back
Next arrow_forward
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.