Operators#

Add#

The Add block is used to add any two values together and reports the sum.

VEXcode blocks stack of code containing an add block.#
  ((0) + (0))

The Add block can accept decimals, integers, or numeric blocks.

The Add block fits in blocks that accept circular spaces, and can accept other circular blocks in it as well.

In this example, the 123 Robot will move forward for 30 mm.

VEXcode blocks stack of code containing a when started block, and a drive forward for 10 plus 20 mm block.#
  when started :: hat events
  drive [forward v] for ((10) + (20)) [mm v] ▶

Subtract#

The Subtract block is used to subtract one value from another and reports the difference.

VEXcode blocks stack of code containing a subtract block.#
  ((0) - (0))

The Subtract block can accept decimals, integers, or numeric blocks.

The Subtract block fits in blocks that accept circular spaces, and can accept other circular blocks in it as well.

In this example, the 123 Robot will move forward for 20 mm.

VEXcode blocks stack of code containing a when started block, and a drive forward for 30 minus 10 mm block.#
  when started :: hat events
  drive [forward v] for ((30) - (10)) [mm v] ▶

Multiply#

The Multiply block is used to multiply any two values together and reports the product.

VEXcode blocks stack of code containing a multiply block.#
  ((0) * (0))

The Multiply block can accept decimals, integers, or numeric blocks.

The Multiply block fits in blocks that accept circular spaces, and can accept other circular blocks in it as well.

In this example, the 123 Robot will move forward for 20 mm.

VEXcode blocks stack of code containing a when started block, and a drive forward for 2 multiplied by 10 mm block.#
  when started :: hat events
  drive [forward v] for ((2) * (10)) [mm v] ▶

Divide#

The Divide block is used to divide the first value by the second value and reports the dividend.

VEXcode blocks stack of code containing a divide block.#
  ((0) / (0))

The Divide block can accept decimals, integers, or numeric blocks.

The Divide block fits in blocks that accept circular spaces, and can accept other circular blocks in it as well.

In this example, the 123 Robot will move forward for 20 mm.

VEXcode blocks stack of code containing a when started block, and a drive forward for 100 divided by 5 mm block.#
  when started :: hat events
  drive [forward v] for ((100) / (5)) [mm v] ▶

Random#

The Random block is used to report a random value between the lowest and highest values in the block.

VEXcode blocks stack of code containing a random operator block.#
  (pick random (1) to (10))

The Random block can accept decimals, integers, or numeric blocks.

In this example, the 123 Robot will move forward for a random distance between 10 and 30 mm.

VEXcode blocks stack of code containing a when started block, and a drive forward for pick random 10 to 30 mm block.#
  when started :: hat events
  drive [forward v] for (pick random (10) to (30)) [mm v] ▶

Greater than#

The Greater than block is used to report if the first value is larger (greater) than the second value.

VEXcode blocks stack of code containing a greater than block.#
  <(50) > (0)>

The Greater than block can accept decimals, integers, or numeric blocks.

The Greater than block reports True when the first value is larger than the second value and False when the first value is smaller than or equal to the second value.

The Greater than Boolean block reports a true or false value and fits in blocks with hexagonal (six-sided) spaces.

In this example, the 123 Robot will move in forward for 3 steps, because 50 > 0 returns True.

VEXcode blocks stack of code containing a when started block, an if 0 greater than 50 then block, a drive forward for 3 steps block, and an end block.#
  when started :: hat events
  if <(50) > (0)> then
  drive [forward v] for (3) [steps v] ▶
  end

Less than#

The Less than block is used to report if the first value is less (smaller) than the second value.

VEXcode blocks stack of code containing a less than block.#
  <(0) < (50)>

The Less than block can accept decimals, integers, or numeric blocks.

The Less than block reports True when the first value is smaller than the second value and reports False when the first value is greater than or equal to the second value.

The Less than Boolean block reports a true or false value and fits in blocks with hexagonal (six-sided) spaces.

In this example, the 123 Robot will move forward for 20 mm, because 0 < 50 returns True.

VEXcode blocks stack of code containing a when started block, an if 0 less than 50 then block, a drive forward for 3 steps block, and an end block.#
  when started :: hat events
  if <(0) < (50)> then
  drive [forward v] for (3) [steps v] ▶
  end

Equal to#

The Equal to block is used to report if the first value is the same as, or equal to, the second value.

VEXcode blocks stack of code containing an equal to block.#
  <(0) = (50)>

The Equal to block can accept decimals, integers, or numeric blocks.

The Equal to block reports True when the two values are exactly the same and reports False when the two values are not the same.

The Equal to Boolean block reports a true or false value and fits in blocks with hexagonal (six-sided) spaces.

In this example, the 123 Robot will move forward for 20 mm, because 20 = 20 returns True.

VEXcode blocks stack of code containing a when started block, an if 20 is equal to 20 then block, a drive forward for 3 steps block, and an end block.#
  when started :: hat events
  if <(20) = (20)> then
  drive [forward v] for (3) [steps v] ▶
  end

And#

The And block is used to report if two Boolean conditions are both true.

VEXcode blocks stack of code containing an And block.#
  <<> and <>>

The And block reports True when both conditions are true and reports False when one, or both, of the conditions are false.

The And Boolean block reports a true or false value and fits in blocks with hexagonal (six-sided) spaces.

In this example, if the Eye Sensor detects a red object and the 123 Robot is moving at the same time, the 123 Robot will stop moving. Otherwise, the 123 Robot will keep moving forward.

VEXcode blocks stack of code containing a when started block, a drive forward block, a wait until eye detects red? and not drive is done? block, and a stop driving block.#
  when started :: hat events
  drive [forward v]
  wait until <<eye detects [red v]?> and <not <drive is done?>>>
  stop driving

Or#

The Or block is used to report if one of two Boolean conditions are true.

VEXcode blocks stack of code containing an or block.#
  <<> or <>>

The Or block reports True when one (or both) of the conditions are true and reports False when both of the conditions are false.

The Or Boolean block reports a true or false value and fits in blocks with hexagonal (six-sided) spaces.

In this example, if the Eye Sensor detects a red or green object, the 123 Robot will stop. Otherwise, the 123 Robot will keep moving forward.

VEXcode blocks stack of code containing a when started block, a drive forward block, a wait until eye detects red ? or eye detects green ? block, and a stop driving block.#
  when started :: hat events
  drive [forward v]
  wait until <<eye detects [red v] ?> or <eye detects [green v] ?>>
  stop driving

Not#

The Not block is used to report the opposite (inverse) of the reported Boolean value.

VEXcode blocks stack of code containing a Not block.#
  <not <>>

The Not block reports True when the Boolean block inside reports false and reports False when the Boolean block inside reports true.

The Not Boolean block reports a true or false value and fits in blocks with hexagonal (six-sided) spaces.

In this example, if the Eye Sensor detects a red object and the 123 Robot is moving at the same time, the 123 Robot will stop moving. Otherwise, the 123 Robot will keep moving forward. The Not block is used to check if the 123 Robot is moving, by saying when the 123 Robot is Not done driving.

VEXcode blocks stack of code containing a when started block, a drive forward block, a wait until eye detects red? and not drive is done? block, and a stop driving block.#
  when started :: hat events
  drive [forward v]
  wait until <<eye detects [red v]?> and <not <drive is done?>>>
  stop driving

Round#

The Round block is used to round the inputted value to the nearest integer.

VEXcode blocks stack of code containing a Round block.#
  (round (0))

The Round block can accept decimals, integers, or numeric blocks.

Decimals that are 0.5 or greater round up and decimals less than 0.5 round down.

The Round block fits in blocks that accept circular spaces, and can accept circular blocks in them as well.

In this example, the 123 Robot will move forward for the rounded number of 20 mm.

VEXcode blocks stack of code containing a when started block, and a drive forward for round 19.76 mm block.#
  when started :: hat events
  drive [forward v] for (round (19.76)) [mm v] ▶

Function#

The Function block is used to perform a selected math function.

VEXcode blocks stack of code containing a function block.#
  ([abs v] of (0))

The Function block can accept decimals, integers, or numeric blocks.

The available functions are:

  • abs - absolute value

  • floor - rounds down to the nearest integer

  • ceiling - rounds up to the nearest integer

  • sqrt - square root

  • sin - sine

  • cos - cosine

  • tan - tangent

  • asin - arcsine or the inverse of sine

  • acos - arccosine or the inverse of cosine

  • atan - arctan or the inverse of tangent

  • ln - the natural logarithm base e

  • log - logarithm base 10

  • e ^ - powers of e

  • 10 ^ - powers of 10

The Function block fits in blocks that accept circular spaces, and can accept circular blocks in them as well.

In this example, the 123 Robot will move forward for 20 mm.

VEXcode blocks stack of code containing a when started block, and a drive forward for abs of -20 mm block.#
  when started :: hat events
  drive [forward v] for  ([abs v] of (-20)) [mm v] ▶

Remainder#

The Remainder block is used to divide the first value by the second value and report the remainder.

VEXcode blocks stack of code containing a remainder block.#
  (remainder of (0) / (0))

The Remainder block can accept decimals, integers, or numeric blocks.

Numbers that divide evenly will report a remainder of zero.

The Remainder block fits in blocks that accept circular spaces, and can accept circular blocks in them as well.

In this example, the 123 Robot will move forward for 20 mm.

VEXcode blocks stack of code containing a when started block, and a drive forward for remainder of 100mm divided by 40mm block.#
  when started :: hat events
  drive [forward v] for (remainder of (100) / (40)) [mm v] ▶