Variables

Now we will learn about variables, they are ways that we can store information in our program. We can store values with them. For example you could use them to store the value of a sensor, or the speed of your robot, or anything else you could imagine.

To create a variable we will go to the the Variables tab and click on “Make a variable”.
Then it will ask you to name the variable, I will call mine “testing”.
Once it is made it will show up as a block on the panel to the left.
The check mark controls if you can see the variable on the screen in the top right corner.


Then we will learn about two of the blocks in the variables tab:

  • “Set __ to 0”
    • This block will set the variable to the value in the box at the end, you can give it a number, or even put another variable in it to set it to that value.
  • “Change __ by 1”
    • This block will add 1 to the variable. Again you can put any number into it, or even another variable.

For both of these blocks we need to select which variable we want to change from the drop down menu.

You can also check out the “Operators” tab. It has different math options that we can use, so rather than just set it to a value or another variable we can have it do some math.

Example program:

This program will set testing to 5 when you press the green flag, and add 1 to testing every time you press “space”.