In this video, you will use variables to change the speed at which Tera moves toward the mousepointer. By this time, you should have a fully functioning Paint with Tera project. Terachanges colors, stamps, and moves toward the mouse pointer. But, what if you wanted togive 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 variableto manipulate that value.
To make a variable, click on the data menu, then 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 10 steps” block. Test your program.
Tera spins, but doesn’t move. That’s because the sprite is moving “speed” steps. Lookat the value of “speed” in the orange box in the top left corner. It equals “0.”
Tera is moving 0 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 1” 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 touse an event like you learned about on Day 3. 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 1” block. Test it by pressing the up arrow. Tera’sspeed increases by one. You successfully changed the value of the speed variable!
To slow down Tera, drag out another “change speed by” block. This time, make the valuenegative 1. Attach another “When space key is pressed” event, and change the valueto “down arrow.” You can now use the up and down arrows to make Tera move faster orslower. Test it out!
Now, customize your project. Change Tera’s costume by going to the costumes tab and addinga new sprite from the library. Also, try drawing on a costume to see its effect. Test it outto see your colorful creation.
Change the title to match your creation.
Finally, let people know how to use your project. Click on “See Project Page.” Under “Instructions”tell people how to use this project. Make sure to mention that the up arrow key willspeed 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 outand see what they can create. Now, it’s your turn!
1. Create a variable named “Speed,” and put it into the “move 10 steps” block.
2. Make the variable’s value increase and decrease using the “change speed by” blockand key presses. 3. Customize your project by changing thecostume and the project’s title. 4. Write instructions letting people knowhow to use this project.