Switch#

Introduction#

Switch blocks enable students to write Python code directly within a block-based environment. This approach helps bridge the gap between block-based and text-based programming. By allowing users to see how block commands convert into Python, Switch blocks make it easier to learn text-based coding techniques within a familiar interface. Using Switch blocks can simplify advanced logic, calculations, and function calls while still using normal Blocks.

Stack#

The Switch Stack block is used to execute Switch Python commands typed within the open space of the block.

They are shaped to attach above or below other action blocks.

a VEXcode Switch Blocks Example showing a Switch Stack Block#
 [] :: custom-switch

Switch Stack blocks can be used for single lines of Switch Python commands or multiple lines.

In order for a Switch Stack block to function as intended, the Switch Python commands must be entered with the correct spelling, punctuation, and indentation.

Example coming soon!

C Block#

The Switch C Block block is used to loop the blocks within until the condition in the open space of the block is met.

They are shaped to attach stack or other C blocks above, below, or inside them.

a VEXcode Switch Blocks Example showing a Switch C Block#
if [] :: custom-switch
end

Some possible Switch Python commands to use with the Switch C block include:

  • while

  • if

  • for

In order for a Switch C block to function as intended, the Switch Python commands must be entered with the correct spelling, punctuation, and indentation.

Example coming soon!

C Expandable#

The Switch C Expandable block is used to loop the blocks within a specific branch when the condition in the open space of the block is met. Additional branches can be added by expanding the block.

They are shaped to attach stack and other C blocks above, below, or inside them.

a VEXcode Switch Blocks Example showing a Switch C Expandable block#
if [] :: custom-switch-expand
end

Some possible Switch Python commands to use with the Switch C Expandable block include:

  • while

  • if

  • for

In order for a Switch C Expandable block to function as intended, the Switch Python commands must be entered with the correct spelling, punctuation, and indentation.

Example coming soon!

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>

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

  <[controller.button5.pressing() and controller.button7.pressing()] :: 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 >=

  <[drone.inertial.get_heading() > 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.

Example coming soon!

Reporter#

The Switch Reporter block is used to return a numeric value. These conditions are defined with Switch Python functions.

They are shaped to fit inside any blocks with circular inputs.

a VEXcode Switch Blocks Example showing a Switch Reporter Block#
([] :: custom-switch)

Switch Reporter blocks can be used for single lines of Switch Python functions that directly will report a numeric value.

Math functions can be used to calculate values within a Switch Reporter block. This includes, but is not limited to:

  • Addition: +

  • Subtraction: -

  • Division: /

  • Multiplication: *

  ([drone.inertial.get_heading() + 45] :: custom-switch)

In order for a Switch Reporter block to function as intended, the Switch Python commands must be entered with the correct spelling, punctuation, and indentation.

Example coming soon!

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 action 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.

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.

Example coming soon!