Variables Practice in Blocks
In Blocks, the Variable menu will first appear empty.

Once variables are created, they will populate in the menu.

HOWEVER, if a variable is not used when a program is saved then exited, it will be removed from the list again upon reopening the program. This is helpful for clearing unused or variables made by mistake, but may cause confusion for students of why something has been deleted.
Variable Activity
In a new OpMode, locate the telemetry blocks under Utilities. Add two for displaying numerical data to the OpMode's loop.
The keys will be set to "Answer 1" and "Answer 2" as seen below:

Create a variable called "A" and one called "B". Make "A" the number for the first telemetry and "B" for the second:

Right now, our variables don't equal anything. Try saving your OpMode and seeing what happens when trying to run it.
Setting Variables
Let's start with using Constant Variables. We're set the variables during initialization so need to add the appropriate blocks here from the Variable menu:

Now "A" and "B" can be set to a value using a number block from the Math menu. For this example, "A" is being set to 5 and "B" to 23:

What happens if you save and test the OpMode now?
Adding Math
With our variables set, we can have the robot do some math for us to test out our variables!
Using the Math menu we can choose different equations to add to our telemetry:

Save and test your OpMode!

Consider:
Last updated
Was this helpful?

