Using Switch Blocks to Transition from Blocks to Text-Based Coding in VEXcode IQ (2nd gen)

Switch incorporates familiar elements of block-based programming and integrates text-boxes where text commands can be typed. View the following video to see an example of Python code being entered into a Switch block.

Note: Switch Blocks are only compatible with Python.


Switch provides students a natural bridge from Blocks into text-based coding. As students gain familiarity with the logic and sequencing of commands, they can begin to convert a project one block at a time. The process of converting a block into a Switch block is shown in this video.

This allows students to continue working with the logic flow of a block-based program where they can physically see things like the wrapping of a loop around other blocks while also beginning to experiment with text commands themselves. Once the blocks are converted to Switch, students can easily change parameters and begin to understand the syntax of the text command. This section will walk you through a student's use of Switch to explain how you can use these blocks in a VEXcode project.

Getting Started with Switch Blocks

To get started with coding with Switch Blocks, you must have:

  • A computer (not a mobile device).
  • A 2nd Gen IQ Brain.

VEXcode IQ Code Viewer menu with the C++ option grayed out and labeled as disabled. The Python option in the Code Viewer is still enabled.

When a Block is converted to a Switch Block, C++ in the Code Viewer will be disabled.

Converting Blocks to Switch

Convert a Single Block to Switch

Drive for block in the VEXcode IQ Workspace with its context menu opened. The menu has six options that read Duplicate, Disable Block, Delete Blocks, Block Help, Convert Block to Switch Block, and Read Block.

Right-click on the Block you want to convert to a Switch Block.

Drive for block in the VEXcode IQ Workspace with its context menu opened. The Convert Block to Switch Block option is selected.

Select Convert Block to Switch Block.

Drive for block that has been converted to a Switch block, and now has Python code that reads drivetrain.drive_for(FORWARD, 10, INCHES).

The Block will now be switched to a Switch Block with the same parameters.

VEXcode IQ Toolbar with the Undo icon highlighted to the left of the Redo icon.

To turn a Switch Block back into a Block after conversion select the Undo button.

Convert Multiple Blocks to Switch

Drive for block that is at the top of a stack of blocks has its context menu opened. There is another option in the Context menu now that reads Convert Stack to Switch Block, this is directly below the Convert Block to Switch Block option.

Right-click the top of the stack you wish to convert to a Switch Block.

Drive for block that is at the top of a stack of blocks has its context menu opened and the Convert Stack to Switch Block option selected.

Select Convert Stack to Switch Block.

The entire stack of three blocks has been converted into one Switch block all together, with one line of Python for each individual block command.

The Block you right-clicked and all Blocks underneath it will be converted to a Switch Block.

Convert Blocks Inside a Wrapper to Switch

You can convert a Wrapper and all of its content to Switch with one click.

Repeat block that is containing other blocks has its context menu opened. The Convert to Switch Block options have changed because this is a C block, and now read Convert Wrapper to Switch Block and Convert Wrapper and Contents to Switch Block.

Right-click the Wrapper you want to convert.

Repeat block that is containing other blocks has its context menu opened and the Convert Wrapper and Contents to Switch Block option selected.

Select Convert Wrapper and Contents to Switch Block.

The entire stack with a wrapper block and nested blocks has been converted into one Switch block all together. There is one corresponding line of Python for each block command.

All of the contents of the Wrapper will be converted to a single Switch Block.

Use a Switch Block

Add a Switch Block from the Toolbox

Click and drag a Switch Block from the Toolbox, as shown in this video.

Type in a Switch Block

Select the Switch Block's text field, then enter your desired command as shown in this video.

Copy and Paste Text Inside a Switch Block

Click and drag to highlight text in the Switch Block. Right-click and select Copy. Next, click inside another Switch Block. Finally, right-click and select Paste to transfer the text, as shown in this video.

Additional Switch Blocks

Switch blocks follow the same shape conventions as other blocks. The table here shows the comparison between the block shape, its meaning, and the Switch blocks of the same type.

Block Shape Description Block Examples Switch Examples
Hat blocks Start a stack of blocks and are shaped to attach blocks below them. My Blocks Definition hat block. Switch hat block. The Python code reads def print_name.
Stack blocks Perform main commands. They are shaped to attach above or below other stack blocks. Drive for stack block. Switch stack block. The Python code reads drivetrain.drive_for(FORWARD, 200, MM).
Boolean blocks Return a condition as either true or false and fits inside any blocks with hexagonal (six-sided) inputs for other blocks. Pressing bumper boolean block. Switch boolean block. The Python code reads left_bumper.pressed().
Reporter blocks Report values in the form of numbers and fits inside any blocks with oval inputs for other blocks. Timer value reporter block. Switch reporter block. The Python code reads brain.timer_time(SECONDS).
C blocks Loop the block(s) within them or check if a condition is true or false. They are shaped to attach stack blocks above, below, or inside them. Forever C block. If then else C block. Switch C block. The Python code reads while true. Switch C expandable block. The Python code reads if left_bumper.pressed(), else.

 

1  Weintrop, David, and Uri Wilensky. "How block-based, text-based, and hybrid block/text modalities shape novice programming practices."  International Journal of Child-Computer Interaction 17 (2018): 83-92

For more information, help, and tips, check out the many resources at VEX Professional Development Plus

Last Updated: