You are on page 1of 5

Variables

A variable is the name for a place where you can store information.

They can remember things such as the score or a players name or a


characters speed.

Variable Video
What do we use Variables for?
Variables are needed to run all but the most simple computer
programs.
As a program runs, it needs to hold information in its memory.
This may be a number, the answer to a question or something
else.
Variables allow us to store, change and access this information as
the program runs.

The colours of these


rabbits may be stored
as a Variable
Creating a variable
You can create a variable to use in your program
using the “Data” section of the blocks palette.
Once a variable has been created, new blocks
appear in the blocks palette ready for you to use.

Give the variable a


name that will help you
remember what it does.
Using a variable
Variables can be used to change a sprite’s
speed. This simple script shows you how.
1. Set the value of a variable.
Create this script. Use the “set
steps 0 block and change the
number to 5, drag the “move 10
steps block onto the script but
drop the “steps” variable block over
the “10”.

Here “steps” means 5, as the value


has been set above.
Using a variable
Variables can be used to change a sprite’s
speed. This simple script shows you how.
2. Use the “change steps by 1” block
to increase the value of the variable
“steps” by 1. Put it inside the
“forever” block, the cat will keep
getting faster.

The “steps” variable keeps on increasing as


the “forever” loop goes round and round

You might also like