Using Switch Blocks to Transition from Blocks to Text-Based Coding

Switch incorporates familiar elements of block-based programming and integrates text-boxes where text commands can be typed.

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. 

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

VEXcode IQ Code Viewer interface showing Python code. At the bottom of the image, there are two buttons: 'Python' (selected) and 'C++ Disabled', emphasizing that C++ is not available when a Switch Block is in the workspace.

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

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

Select Convert Block to Switch Block.

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

undo.png

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

Convert Multiple Blocks to Switch

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

Select Convert Stack to Switch Block.

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.

Right-click the Wrapper you want to convert.

Select Convert Wrapper and Contents to Switch Block.

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.

Type in a Switch Block

Select the Switch Block's text field, then enter your desired command.

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.

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. A My Block labeled 'define Print Name'. A Switch Block showing a Python function definition: 'def print_name:'
Stack blocks Perform main commands. They are shaped to attach above or below other stack blocks. Block-based coding element showing 'drive forward for 200 mm' with dropdown menus for direction and unit. Switch Block containing the function call '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. Boolean block-based coding element showing 'LeftBumper pressed?' with a dropdown menu for 'LeftBumper'. Switch block containing the function call 'left_bumper.pressed()'.
Reporter blocks Report values in the form of numbers and fits inside any blocks with oval inputs for other blocks. Reporter block-based coding element displaying 'timer in seconds'. Switch block containing the function call '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. A Forever Block with no blocks inside of it. An If then else Block with no blocks inside of it. Switch block containing the python code `while True:`. Switch block containing the python code `if left_bumper.pressed():` and beneath it, `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: