top of page

Variables Blocks

What is variable?

Variable is a reserved memory location to store values. Memory location has a label and a value. The value can be dynamic and can be changed programmatically.

Variables can only hold one value at a time, unlike lists. These values can be either numbers or strings.


ree



How to create your own variable?

The clickable button “make variable” in variables category, allows the user to create new variable.

Scratch does not allow variables to be created by a script as it runs. Instead, variables are created with the "Make a Variable" button



ree


ree


ree


What is the difference between “for all sprite”, “for this sprite only” and “cloud variable”?

When you create your own variable, you will get two options of radio buttons and one checkbox option.


ree



For all sprite:

This is a global variable. Global variables can be read and changed by any sprite, or the Stage. All variables are stored in RAM, and default to the values in the file it originates from. When creating a variable, by default ‘for all sprite is applicable.


For this sprite only:

This is a local variable. Local variable can be created by selecting “for this sprite only” option. These variables can only be changed by their owner but can be read by other sprites. The Stage cannot have local variables.


Cloud variable:

Cloud variables are variables that are stored on the cloud server. In Scratch 3.0, cloud variables only support numerical data, and all are limited to 256 characters, you are allowed 10 cloud variables in a single project.


How to rename the variable?

You can rename the variable in two ways. One you can right click on the variable and select the option “rename”.



ree


Another way – you can programmatically change using any of the 4 blocks.



ree


ree


How to delete the variable?

You can delete in two ways. One you can right click on the variable and delete.



ree


Another way – Use any of the 4 blocks to delete.


ree



How to show the variable on the stage?

There are two ways to show. One is checking the check box next to the variable



ree


Another one – use the block “show variable”



ree


How to hide the variable from the stage?

There are two ways to hide the variable from the stage. One is unchecking the checkbox next to the variable.



ree


Another one – use the “hide variable” block



ree


How to use the variable with other blocks?

The variable we create is a reporting block and can be used with other blocks like operators.


ree


ree



How to use “set variable to ()” block?

This block allows to initiate the value for the variable.


ree



How to use “change variable by ()” block?

This block allows to change the variable by given value



ree


Exercise 12


1. In nature what dynamically changes? Example air temperature, wind speed. Explain.


2. In nature what doesn’t change for lifetime? Example Speed of the earth rotation. Explain?





Kommentare

Mit 0 von 5 Sternen bewertet.
Noch keine Ratings

Rating hinzufügen
bottom of page