Hat#

The Switch Hat block is used to run the attached stack of blocks when the function is called.

They are shaped to attach above other stack blocks.

a VEXcode Switch Blocks Example showing a Switch hat block#
[                                                  ] :: hat custom-switch

The attached stack of blocks are a function. The Switch Hat block is used to define the name of the function and any optional parameters.

To define the function, select the open space of the block indicated in the image here and begin typing.

Image of a Switch Hat block used to define functions and parameters in programming, with an example of function syntax.

Parameters should be enclosed in parentheses and followed by a colon as shown below. If a function has no parameters, use closed parentheses: ().

a VEXcode Switch Blocks Example showing a Switch hat block with python function that has a parameter#
[def function_name(parameter):] :: hat custom-switch

In order for a Switch Hat 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 Drivetrain will move forward for 400 Millimeters when the drive_400() function is called.

a VEXcode Switch Blocks Example showing a Switch hat block and a drive forward block#
[drive_400()] :: hat custom-switch
drive [forward v] for (400) [mm v] ▶