Skip to content

Please update your browser

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

Transcript

In this video, you will use variables to change the speed at which Tera moves towards the mouse pointer.

By this time, you should have a fully functioning Paint With Tera project.

Tera changes colors, stamps, and moves towards the mouse pointer.

But, what if you want to give the user some control over how fast Tera moves?

Tera's speed is determined by the number in the move 10 steps block.

Use a variable to manipulate that value.

To make a variable, click on Make a Variable.

Because you want the variable to determine how fast Tera moves, name it speed.

Click OK.

Notice that creating the variable caused new blocks to appear.

Drag out the speed variable, and place it in the move ten steps block.

Test your program.

Tera spins, but doesn't move.

That's because the sprite is moving speed steps.

Look at the value of speed in the orange box in the top left corner.

It equals zero.

Tera is moving zero steps each time this block runs, which is why it isn't moving.

To change the value of the variable, drag out the orange change speed by one block.

Clicking on it will make Tera resume moving.

With each click the value of the variable speed increases.

In order to change the value of speed while the program is running, you need to use an event, like you learned about on day three.

Events trigger code to run.

Pull out the when key pressed block.

Change the value in the block to up arrow and attach it to the change speed by one block.

Test it by pressing the up arrow.

Tera's speed increases by one.

You successfully changed the value of the speed variable.

To slow Tera down, drag out another change speed by block.

This time, make the value negative one.

Attach another when space key is pressed event and change the value to down arrow.

You can now use the up and down arrows to make Tera move faster or slower.

Test it out.

Now, customize your project.

Change Tera's costume by going to the Costumes tab and adding a new sprite from the library.

Also, try drawing on a costume to see it's effect.

Test it out to see your colorful creation.

Change the title to match your creation.

Finally, let people know how to use your project.

Under Instructions, tell people how to use this project.

Make sure to mention that the up arrow key will speed the sprite up and the down arrow key will slow the sprite down.

Congratulations on building an interactive art project.

Ask a neighbor to try it out and see what they can create.

Now it's your turn.

Create a variable named speed and put it into the move ten steps block.

Make the variable's value increase and decrease using the change speed by block and key presses.

Customize your project by changing the costume and project's title.

And finally, write instructions letting people know how to use the project.

Instructions
  1. Create a variable, name it "Speed," and put it into the "move 10 steps" block.
  2. Make the variable increase and decrease using the "Change speed by" block and key presses.