Using Switch Blocks to Transition from Blocks to Text-Based Coding in VEXcode GO

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

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. 

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.

Converting Blocks to Switch

Note: To get started with coding with Switch Blocks, you must have a computer (not a mobile device).

Convert a Single Block to Switch

drive forward for 100 mm block with the context menu opened. It contains duplicate, disable blocks, 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 forward for 100 mm block with the context menu opened. It contains duplicate, disable blocks, delete blocks, block help, convert block to switch block and read block. The convert block to Switch block is highlighted.

Select Convert Block to Switch Block.

drivetrain.drive_for forward 100 mm in switch block

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

VEXcode GO top menu with the undo button highlighted.

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

Convert Multiple Blocks to Switch

VEXcode GO with the context menu open on the first block, drive forward for 100 mm.

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

Same image as above, highlighted the convert stack to switch block

Select Convert Stack to Switch Block.

VEXcode GO, when started, drivetrain.drive_for forward, 100, mm. drivetrain.turn_for right 90 degrees and console.print VEXcode

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

Convert Blocks Inside a C Block to Switch

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

Right-click the C Block you want to convert.

Same image as above, with highlighted convert C block and its contents to Switch block

Select Convert C Block and its Contents to Switch Block.

VEXcode GO Python, when started, for repeat_count in range(4), then the three lines below is drivetrain.drive_for(FORWARD, 100, MM), drivetrain.turn_for(RIGHT, 90), and then wait(5, MSEC)

All of the contents of the C Block 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 ShapeDescriptionBlock ExamplesSwitch Examples
Hat blocksStart a stack of blocks and are shaped to attach blocks below them.define print name block.def print_name() in a hat switch block
Stack blocksPerform main commands. They are shaped to attach above or below other stack blocks.drive forward for 100 mm blockdrivetrain.drive_for(FORWARD, 100, MM) in Switch block.
Boolean blocksReturn a condition as either true or false and fits inside any blocks with hexagonal (six-sided) inputs for other blocks.bumper pressed blockbumper.is_pressed() in a Switch block
Reporter blocksReport values in the form of numbers and fits inside any blocks with oval inputs for other blocks.timer in seconds blocktimer.time(SECONDS) in Switch block
C blocksLoop 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 block and if else block while True block in a C shape block. If bumper.is_pressed() and else: in an E shape block

 

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: