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.

Switch Hat block for defining functions in programming, showing parameters and function name input area.

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: ().

Diagram illustrating the Switch Hat block for defining functions and parameters in programming.

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.

Illustration of a Switch Hat block used to define a function with parameters in a programming environment.