In this lesson, you will learn what a variable is and what each variable block does. You will also learn how to create lists in variables.
The variable blocks are the ones that are colored in orange.
So, what is a variable?
Well, a variable is like a box with a label that’s used to store information like numbers and text.
Variables are very helpful. Imagine you have ten “move 5 steps” blocks and want to change the value. You won’t like it to have to change the value of the ten blocks. A variable is very helpful at those times.
If you have a variable, you’d have to change the value only once.
Now, let’s make a variable.
Step 1: Click “Make a Variable”.
Step 2: Write variable name in the blank and then click “OK”. We’re going to make a variable for all sprites, but you can later make a variable for only one sprite.
We’re done. You can click the checkbox to hide the variable if you want. Now, let’s learn about the blocks.
The “set my variable to 0” block
The “set my variable to 0” block sets the variable to the specified value. If you have more than one variable, you can select the variable name from the drop-down menu and change the value 0 to any number or text you want.
The “change my variable by 1” block
The “change my variable by 1” block changes the variable to the specified number. If you have more than one variable, you can select the variable name from the drop-down menu and change the value 1 to any number you like.
The “show variable my variable” block
The “show variable my variable” block shows the variable. If you have more than one variable, you can select the variable name from the drop-down menu.
The “hide variable my variable” block
The “hide variable my variable” block hides the variable. If you have more than one variable, you can select the variable name from the drop-down menu.
The “my variable” block
The “my variable” reports value of the variable. Note: The block “my variable” won’t be “my variable” if the variable name is different. It will always be the name of your variable. If you have many variables, there will be many of this block.
You can change a variable’s readout by right-clicking the variable on the stage. You will see a drop-down menu with three options, the “normal readout” option, “large readout” option, and “slider” option.
The normal readout option looks like this:
The large readout option looks like this:
The slider option looks like this:
Now, let’s learn about lists.
In beginner language, lists are just like lists on paper. A list contains more than 1 item and can contain both text and numbers.
Let’s make one.
Step 1: Click “Make a List”.
Step 2: Click write the list name inside the blank and click “OK”. We’re going to make a list for all sprites, but later, you can make a variable for only 1 sprite.
And we’re done. Our list doesn’t have any items. Click the plus sign next to the length 0 written on the list.
You will see a red rectangle in the list, replacing the text that said, “empty.” Write the item name inside and click anywhere else outside the rectangle. You can add many different things.
Now, let’s learn about what each block does.
The “Animals” block
The “Animals” block isn’t called Animals because it has something to do with animals. It’s called Animals because the list name is Animals. If you have a list with another name, you’ll have the block with the list name. The block reports all items in the list. You can click the checkbox to hide it if you want.
The “add thing to Animals” block
The “add thing to Animals” block adds the name of the thing which is thing, but you can change it to anything you like to the list selected from the drop-down menu.
The “delete 1 of Animals” block
The “delete 1 of Animals” block deletes the specified number of item in the list selected from the drop-down menu. You can write any number that is less than or equals to the length of your list in instead of the 1.
The “delete all of Animals” block
The “delete all of Animals” block deletes all the items in the list selected from the drop-down menu.
The “insert thing at 1 of Animals” block
The “insert thing at 1 of Animals” block inserts an item at the specified position in the list selected from the drop-down menu. You can change the word and number to any word and number you like, but it has to be less than, greater than 1 number, or equals the length of the list.
The “replace item 1 of Animals with thing” block
The “replace item 1 of Animals with thing” block replaces the specified item number in the list selected from the drop-down menu with text. You can change the thing to anything you like.
The “item 1 of Budgie Mutations” block
The “item 1 of Budgie Mutations” block reports the specified item number of the list selected from the drop-down menu. You can write a number that is less than or equals the length of the list.
The “item # of thing Animals” block
The “item # of thing Animals” block reports the number of the specified word in the list selected from the drop-down menu. You can write any word instead of thing, but it has to be a word that is in your list.
The “length of Animals” block
The “length of Animals” block reports the length of the list selected from the drop-down menu.
The “Animals contains thing?” block
The “Animals contains thing?” block reports true if the list contains specified item.
Note: The list must contain exactly the same specified item. You can select list name from the drop-down menu and set the word thing to anything you want.
The “show list Animals” block
The “show list Animals” block shows the list selected from the drop-down menu.
The “hide list Animals” block
The “hide list Animals” block hides the list selected from the drop-down menu.