Variables#
To put a variable in the Monitor Console, drag and drop its Reporter block to the Monitor Icon on the right side of the screen.
Numeric variable#
The Numeric variable block is used to report the numeric value assigned to the variable. Variables are created with global scope by default.
(myVariable)
Use the Set numeric variable block to set or update the numeric value of a variable.
The Numeric Variable reporter block is used in blocks with circular spaces.
Variables are created using the Make a Variable button.
In this example, the variable driveLength
is set to 500 and used in the Drive for block. This makes the Drive for block move forward for 500 mm.
when started :: hat events
set [driveLength v] to [500]
drive [forward v] for (driveLength) [mm v] ▶
Set numeric variable#
The Set numeric variable block is used to set a numeric variable to a given value. Variables are created with global scope by default.
set [myVariable v] to [0]
Choose which numeric variable to use. Numeric variables can also be renamed or deleted.
The Set numeric variable block can accept decimals, integers, or numeric blocks.
In this example, the variable driveLength
is set to 500 and used in the Drive for block. This makes the Drive for block move forward for 500 mm.
when started :: hat events
set [driveLength v] to [500]
drive [forward v] for (driveLength) [mm v] ▶
Change numeric variable#
The Change numeric variable block is used to change a variable by the given value.
change [myVariable v] by (1)
Choose which numeric variable to use - the selected variable can also be renamed or deleted.
The Change numeric variable block can accept decimals, integers, or numeric blocks.
In this example, the variable driveLength
is changed by 500 and used in the Drive for block. This makes the Drive for block move forward for 500 mm.
when started :: hat events
change [driveLength v] by [500]
drive [forward v] for (driveLength) [mm v] ▶
Boolean variable#
The Boolean variable block is used to report the value of a Boolean variable. Variables are created with global scope by default.
<myBoolean>
Use the Set boolean variable block to set or update the value of a boolean variable.
The Boolean variable block reports a true or false value and is used in blocks with hexagonal (six-sided) spaces.
Boolean variables are created using the Make a Boolean button.
In this example, the driveNow
Boolean variable is set to True
at the start of the project. This makes the Drivetrain drive forward until the driveNow
variable returns False
.
when started :: hat events
set [driveNow v] to <true>
if <driveNow> then
drive [forward v]
end
stop driving
Set Boolean variable#
The Set Boolean variable block is used to set a boolean variable to a given value. Variables are created with global scope by default.
set [myBoolean v] to <true>
Choose which boolean variable to use. Boolean variables can also be renamed or deleted.
Choose a Boolean value.
The Set Boolean variable block can accept hexagonal (six-sided) shaped blocks.
In this example, the driveNow
Boolean variable is set to True
at the start of the project. This makes the Drivetrain drive forward until the driveNow
variable returns False
.
when started :: hat events
set [driveNow v] to <true>
if <driveNow> then
drive [forward v]
end
stop driving
List item#
The List item block is used to report the value of an item in a list.
(item (1) of [myList v])
Choose which list to use. The list can also be renamed or deleted.
Enter the number of the item’s position within the list. Here, the second item in list (item 2) is being reported.
The List item block can accept decimals, integers, or numeric blocks.
In this example, the cardinalHeadings
list stores the degrees for north, east, south, and west. The Drivetrain turns to face item 3, which is set to 180
degrees.
when started :: hat events
set [cardinalHeadings v] to (0) (90) (180) (270)
turn to heading (item (3) of [cardinalHeadings v]) degrees ▶
Replace List item#
The Replace List item block is used to update an item in the list to a new value.
replace item (1) of [myList v] to (0)
Choose which list to use. The list can also be renamed or deleted.
The Replace List item block can accept decimals, integers, or numeric blocks.
In this example, only item 2 of the cardinalHeadings
list is replaced with 90
. The Drivetrain will then turn to a heading of 90
degrees.
when started :: hat events
replace item (2) of [cardinalHeadings v] to (90)
turn to heading (item (2) of [cardinalHeadings v]) degrees ▶
Set List item#
The Set List item block is used to set every item in the list to the entered values. Variables are created with global scope by default.
set [myList v] to (0) (0) (0) (0) (0)
Choose which 2D list to use. The 2D list can also be renamed or deleted.
The Set List item block can accept decimals, integers, or numeric blocks.
In this example, the cardinalHeadings
list stores the degrees for north, east, south, and west. The Drivetrain turns to face item 3, which is set to 180
degrees.
when started :: hat events
set [cardinalHeadings v] to (0) (90) (180) (270)
turn to heading (item (3) of [cardinalHeadings v]) degrees ▶
Length of List#
The Length of List block is used to report the number of items in a list.
(length of [myList v])
Choose which list to use. The 2D list can also be renamed or deleted.
The Length of List reporter block fits in blocks that accept circular spaces.
In this example, the length of the cardinalHeadings
list will be printed to the Console.
when started :: hat events
print (length of [cardinalHeadings v]) ▶
2D List item#
The 2D List item block is used to report the value of an item in a 2D list.
(item (1) (1) of [my2Dlist v])
Choose which 2D list to use. The 2D list can also be renamed or deleted.
Enter the item’s row (first number) and column (second number) position within the list to be reported. Here, the item in position row 2, column 3 in the 2D list is being reported.
(item (2) (3) of [my2Dlist v])
The 2D List item block can accept decimals, integers, or numeric blocks.
In this example, the moveCoordinates
2D List is used to store numeric values that relate to positions on the playground. Assuming that the Robot starts at the coordinate (0, 0)
, the Drivetrain uses the items from (5,1) and (5,2) in the 2D List to move to the coordinate (300, 200)
.
when started :: hat events
set [move_coordinates v] to ((300)(150)) ((500)(200))
drive [forward v] for (item (1)(1) of [move_coordinates v]) [mm v] ▶
turn [right v] for (90) degrees ▶
drive [forward v] for (item (1)(2) of [move_coordinates v]) [mm v] ▶
Replace 2D List item#
The Replace 2D List item block is used to update an item in the 2D list to a new value.
replace item (1) (1) of [my2Dlist v] to (0)
Choose which 2D list to use. The 2D list can also be renamed or deleted.
The Replace 2D List item block can accept decimals, integers, or numeric blocks.
In this example, the Drivetrain will drive forward for 2 seconds. It will record the Robot’s current Y coordinate in the second column of the first row in its moveCoordinates
2D list before stopping.
when started :: hat events
drive [forward v]
wait (2) seconds
replace item (1) (2) of [moveCordinates v] to (position [Y v] in [mm v])
stop driving
Set 2D List item#
The Set 2D List item block is used to set every item in the 2D list to the entered values. Variables are created with global scope by default.
set [move_coordinates v] to ((0)(0)) ((0)(0))
Choose which 2D list to use. The 2D list can also be renamed or deleted.
The Set 2D List item block can accept decimals, integers, or numeric blocks.
In this example, the move_coordinates
2D List is used to store numeric values that relate to positions on the playground. Assuming that the Robot starts at the coordinate (0, 0)
, the Drivetrain uses the items from (1,1) and (1,2) in the 2D List to move to the coordinate (300, 150)
.
when started :: hat events
set [move_coordinates v] to ((300)(150)) ((500)(200))
drive [forward v] for (item (1)(1) of [move_coordinates v]) [mm v] ▶
turn [right v] for (90) degrees ▶
drive [forward v] for (item (1)(2) of [move_coordinates v]) [mm v] ▶
Length of 2D List#
The Length of 2D List block is used to report the number of rows or columns in a 2D list.
length of [my2Dlist v] [rows v]
Choose which 2D list to use. The 2D list can also be renamed or deleted.
Choose which value to report. The 2D list can report either rows or columns.
The Length of 2D List reporter block fits in blocks that accept circular spaces.
In this example, the Robot will print how many rows there are in the moveCoordinates
2D List.
when started :: hat events
print (length of [moveCoordinates v] [rows v]) ▶