Assigns the input value to a variable.
Variables are used as placeholders for values such as numbers or strings of text. Variables allow for a lot of freedom in programming. Instead of having to type out a phrase many times or remember a number, computer scientists can use variables to reference them. Variable values can change throughout a program.
If no variable with the specified name has been created, this block can create a new named variable with the given value. If the variable already exists, its new value will replace its old value.
Change the color input given to the variable “spriteColor.” See how changing the variable value changes what the variable then passes to the change color
block.
A variable can be used several times in a program. Here, the variable “spriteSize” sets all the food sprites to the same size.
If the variable value changes, it only affects the code after it. In this case, "spriteSize" passes one value to the apple and mushroom. It is then set to a new value that it is used in the code for the cherry and beet, but not in the code before it.
Name | Description |
---|---|
value input | The value the variable is being set to |
variable name | The name of the variable. The name can be chosen from a drop-down list or customized using the rename option. |
Found a bug in the documentation? Let us know at documentation@code.org