All pages
Powered by GitBook
1 of 1

Loading...

Variables Practice in Blocks

In Blocks, the Variable menu will first appear empty.

Default Variable menu

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

Variable menu with created variables

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:

Telemetry blocks added to the OpMode

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

Variables added to the telemetry

Right now, our variables don't equal anything. Try saving your OpMode and seeing what happens when trying to run it.

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?

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:

Setting Variables

Adding Math

Adding blocks to set the variables during initialization
Add a value to the variables
Example of math added to the telemetry blocks