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 more functions that animate the android's actions.

In the previous video, you learned that you could make a new block to animate your android.

If you did those same steps for all of your animations, your code would look something like this.

That is one way to create animations.

But as an advanced CS First student, you might notice that many stacks in this code look similar to each other.

Instead of repeating code stacks over and over, make a function or a new block that will achieve the same effect with fewer code blocks.

This saves time and effort and makes your code easier to read.

Create a function that changes the sprite's costume a specific number of times to complete one animated action.

To start, make a new block.

And name it animate action.

Great.

To make the costumes repeat like those in your first animation drag the repeat loop, next costume block, and wait block you previously coded under the defined animate action block.

To make this code stack start and stop at specific times, add a parameter or input to the block's definition.

This parameter will specify how many times the costume should change.

In computer science, a parameter gives information that slightly changes the behavior of the code stack.

For example, the animate action function might switch costumes four times for a certain action, but eight times for another action.

The parameter input specifies how many times the costume switches.

When you add a parameter to a block's definition, it creates an input space so that users can add another block or value to the code.

Right click on the defined block and select edit.

Then click add number input.

Name this input costumes.

Click okay.

Next, drag the newly created costumes parameter inside the repeat loop.

Now, put this block to use.

This example for the happy animation has 10 costumes.

The happy animation needs to cycle through nine next costume blocks to complete the animation.

In this example, the switch costume to happy one block should remain under the defined happy block.

Drag the animate actions block under the switch costume to happy one block.

Change the value in the animate actions block to the create number for your animation.

This example uses nine.

Test the code by clicking the action block you created.

The sprite animates the action just like before.

You now have one animation working but your starter project contains several animations to use throughout your story.

To create those animations, define a new block for each.

And add a switch costume block to set the android to the starting costume.

Next, add an animate action block and enter the number of costumes for the animation.

Do this for all of the sprite's actions.

Then add those actions to your story.

Now it's your turn.

Create a function and use it to define the android actions.

Then add the action blocks throughout your story.

Instructions

  1. Create a function, and use it to define the android actions.
  2. Add the "action" blocks throughout your story!