Boolean#

The Switch Boolean block is used to return a condition as either True or False. These conditions are defined with Switch Python functions.

They are shaped to fit inside any blocks with hexagonal (six-sided) inputs.

a VEXcode Switch boolean Block#
<[                                                                                ] :: custom-switch>

Select the open space of the block indicated in the image here and begin typing.

Illustration of a Switch Boolean block used to evaluate conditions in Python, showing hexagonal input space for commands.

Switch Boolean blocks can be used for single lines of Switch Python functions that directly will report a true or false condition.

Operators can be used to evaluate multiple Switch Python functions in a single Switch Boolean block. This includes:

  • and

  • or

  • not

a VEXcode switch Block example with a boolean block that has a line of switch python functions#
<[left_bumper.pressed() and right_bumper.pressed()] :: custom-switch>

A Switch Boolean block can also combine Switch Python functions with comparison operators to evaluate how a value reported compares to the given number using the following operators:

  • Greater Than: >

  • Less Than: <

  • Equal to: =

  • Additional operators that can be used include <=, !=, and >=

a VEXcode switch block example using a boolean Block with a comparison operator#
<[front_distance.get_distance(MM) > 100] :: custom-switch>

In order for a Switch Boolean block to function as intended, the Switch Python commands must be entered with the correct spelling, punctuation, and indentation. Refer to the Help of each block to see the matching Switch Python command.

In this example, the code will check continuously if the Left Bumper Sensor was pressed. If the sensor is pressed, it will print “Bumper was pressed!” to the Print Console.

a VEXcode switch block expample using a boolean Block with comparison operator#
when started :: hat events
forever
drive [forward v]
if <[left_bumper.pressed()] :: custom-switch> then
print [ Bumper was pressed! ] ▶
end
end