Variables#

Introduction#

The Variables blocks in VEXcode AIR allow for storing and managing data, including numbers, Boolean values, lists, and 2D lists.

To make a variables blocks appear you must first create a variable. Variables are created using the Make buttons in the Variables category. All variables are global by default, meaning they can be used anywhere in the project.

Below is a list of available blocks:

Numeric Variables - Store and modify numbers.

Boolean Variables – Store True or False values.

Lists – Store and manage collections of values.

2D Lists – Store and manage collection of values in a grid.

numeric variable#

The numeric variable reporter block is used to report the numeric value assigned to the variable.

The Numeric variable reporter block.#
    (my_variable)

Parameter

Description

This block has no parameters.

Example

  when started :: hat events
  [Turn to the heading set by the variable.]
  take off to [500] mm ▶
  set [my_variable v] to [90]
  turn to heading (my_variable) degrees ▶

set numeric variable#

The set numeric variable block assigns a value to a numeric variable.

Parameter

Description

variable

The numeric variable to assign a value to. Users can select an existing variable, rename it, or delete it.

value

The number assigned to the variable (can be a whole number, decimal, or numeric block).

Example

  when started :: hat events
  [Turn to the heading set by the variable.]
  take off to [500] mm ▶
  set [my_variable v] to [90]
  turn to heading (my_variable) degrees ▶

change numeric variable#

The change numeric variable block increases or decreases a variable’s value by a given amount.

The Change Numeric Variable stack block.#
    change [my_variable v] by (1)

Parameter

Description

variable

The numeric variable to modify. Users can select an existing variable, rename it, or delete it.

value

The amount to increase or decrease the variable by.

Example

  when started :: hat events
  [Turn to the heading set by the variable.]
  take off to [500] mm ▶
  set [my_variable v] to [90]
  change [my_variable v] by [90]
  turn to heading (my_variable) degrees ▶

Boolean variable#

The Boolean variable block is used to report either a True or False value.

The Boolean Variable reporter block.#
    <my_boolean>

Parameter

Description

This block has no parameters.

Example

  when started :: hat events
  [Take off if the variable is set to True.]
  set [my_boolean v] to <true v>
  if <my_boolean> then
  take off to [500] mm ▶
  end

set Boolean variable#

The set Boolean variable block assigns a True or False value to a Boolean variable.

The Set Boolean Variable stack block.#
    set [my_boolean v] to <true v>

Parameter

Description

variable

The Boolean variable to assign a value to. Users can select an existing variable, rename it, or delete it.

value

A Boolean value (True or False).

Example

  when started :: hat events
  [Take off if the variable is set to True.]
  set [my_boolean v] to <true v>
  if <my_boolean> then
  take off to [500] mm ▶
  end

list item#

The list item block is used to report the value of an item in a list.

The List Item reporter block.#
    (item (1) of [my_list v])

Parameter

Description

index

The position of the item in the list (starting at 1).

variable

The list variable to report an item from. Users can select an existing list, rename it, or delete it.

Example

  when started :: hat events
  [Turn to the heading equal to the 2nd list item.]
  take off to [500] mm ▶
  set [my_list v] to [45] [90] [180]
  turn to heading (item (2) of [my_list v]) degrees ▶

replace list item#

The replace list item block updates a specific item in a list.

The Replace List Item stack block.#
    replace item (1) of [my_list v] to (1)

Parameter

Description

variable

The list variable containing the item to modify. Users can select an existing list, rename it, or delete it.

index

The position of the item in the list (starting at 1).

value

The new value assigned to the specified list item.

Example

  when started :: hat events
  [Turn to the heading equal to the 2nd list item.]
  take off to [500] mm ▶
  set [my_list v] to [45] [90] [180]
  replace item (2) of [my_list v] to (135)
  turn to heading (item (2) of [my_list v]) degrees ▶

set list items#

The set list items block sets every item in the list to the entered values.

The Set List Items stack block.#
    set [my_list v] to [0] [0] [0]

Parameter

Description

variable

The list variable being assigned values. Users can select an existing list, rename it, or delete it.

values

The values to store in the list, entered as individual items.

Example

  when started :: hat events
  [Turn to the heading equal to the 2nd list item.]
  take off to [500] mm ▶
  set [my_list v] to [45] [90] [180]
  turn to heading (item (2) of [my_list v]) degrees ▶

length of list#

The length of list block reports the number of items in a list.

The Length of List reporter block.#
    (length of [my_list v])

Parameter

Description

variable

The list variable to report the length of. Users can select an existing list, rename it, or delete it.

Example

  when started :: hat events
  [Turn to the heading equal to the 2nd list item.]
  take off to [500] mm ▶
  set [my_list v] to [45] [90] [180]
  repeat (length of [my_list v])
  turn [right v] for (item (2) of [my_list v]) degrees ▶

2D list item#

The 2D list item block is used to report the value of an item in a 2D list.

The 2D List Item reporter block.#
    (item (1) (1) of [my_2d_list v])

Parameter

Description

row

The row of the item (starting at 1).

column

The column of the item (starting at 1).

variable

The 2D list variable to report an item from. Users can select an existing 2D list, rename it, or delete it.

Example

  when started :: hat events
  [Turn to the heading equal to list item (2, 2).]
  take off to [500] mm ▶
  set [my_2d_list v] to ([1][45]) ([2][90])
  turn to heading (item (2) (2) of [my_list v]) degrees ▶

replace 2D list item#

The replace 2D list item block updates a specific item in a 2D list.

The Replace 2D List Item stack block.#
    replace item (1) (1) of [my_2d_list v] to (1)

Parameter

Description

row

The row index of the item (starting at 1).

column

The column index of the item (starting at 1).

variable

The 2D list variable containing the item to modify. Users can select an existing 2D list, rename it, or delete it from the drop-down menu.

value

The new value assigned to the specified 2D list item.

Example

  when started :: hat events
  [Turn to the heading equal to list item (2, 2).]
  take off to [500] mm ▶
  set [my_2d_list v] to ([1][45]) ([2][90])
  replace item (2) (2) of [my_2d_list v] to (135)
  turn to heading (item (2) (2) of [my_list v]) degrees ▶

set 2D list items#

The set 2D list items block sets every item in the 2D list to the entered values.

The Replace 2D List Item stack block.#
    set [my_2d_list v] to ([0][0]) ([0][0])

Parameter

Description

variable

The 2D list variable being assigned values. Users can select an existing 2D list, rename it, or delete it.

values

The values to store in the 2D list, entered row by row.

Example

  when started :: hat events
  [Turn to the heading equal to list item (2, 2).]
  take off to [500] mm ▶
  set [my_2d_list v] to ([1][45]) ([2][90])
  replace item (2) (2) of [my_2d_list v] to (135)
  turn to heading (item (2) (2) of [my_list v]) degrees ▶

length of 2D list#

The length of 2D list block reports the number of rows or columns in a 2D list.

The Length of 2D List reporter block.#
    length of [my_2d_list v] [rows v]

Parameter

Description

variable

The 2D list variable to check the length of. Users can select an existing 2D list, rename it, or delete it.

rows/columns

Whether to report the number of rows or column.

Example

  when started :: hat events
  [Turn to the heading equal to list item (2, 2).]
  take off to [500] mm ▶
  set [my_2d_list v] to ([1][45]) ([2][90])
  replace item (2) (2) of [my_2d_list v] to (135)
  repeat (length of [my_2d_list v] [rows v])
  turn [right v] for (item (2) (2) of [my_list v]) degrees ▶