Switch Mode in VEXcode VR
Watch this video to learn about using Switch Blocks in VEXcode VR. You will learn how Switch Blocks support the transition from block-based to text-based programming using the Python coding language. This video covers how to access Switch Mode blocks, the five types of Switch Mode blocks, and how to use Python commands within the Switch blocks.
(upbeat music)
Welcome to today's lesson. In this lesson, we're going to explore how to use the Switch blocks in VEXcode VR and view the Python applications of various block codes in Switch. This is a fantastic way to start learning text-based programming to enhance your coding skills while still having loads of fun with the block-based approach.
Let's start by accessing the Switch mode blocks in VEXcode VR. Launch VEXcode VR from your browser. Select the Switch category. Under the Switch category, there are five types of Switch blocks with different shapes. Each Switch block includes at least one text box for displaying or entering the Python command. The Switch blocks follow the same shape conventions as other blocks we are familiar with.
Let's take a look at how each type of Switch block is used.
Stack blocks: The Stack blocks are the blocks that perform main commands. Instead of specifying a specific behavior like other Stack blocks, the Switch Stack block uses the Python command in its text box to define a specific behavior, such as moving the drivetrain for a given distance, turning the drivetrain for a given number of degrees, setting the position of the VR pen, et cetera. Switch stack blocks can be used for multiple lines of Python commands, adding flexibility to their use in programming. They are shaped to attach above or below other stack blocks.
Boolean blocks: Boolean blocks are the hexagonal blocks that return a condition as either true or false. In contrast to other Boolean blocks that define a condition directly, the Switch Boolean block utilizes a Python statement in its text box to determine the condition. The Python statement can be a sensor status function that returns a Boolean value, a comparison operation, a logical operation, et cetera. The Switch Boolean blocks are used with blocks that accept hexagonal Boolean blocks.
Reporter blocks: Reporter blocks are the oval blocks that report values in the form of numbers. Unlike other reporter blocks that specify the reported value directly, the Switch reporter block uses the Python statement in its text box to define the value to be returned. The Python statement can be a sensor status function that returns a number value, a variable, a mathematical operation, et cetera. The reporter blocks are used with blocks that accept oval reporter blocks.
C blocks: C blocks will loop the blocks within them or check if a condition is true or false. Rather than representing a fixed control flow structure as other C blocks do, the Switch C block uses the Python statement in its text box to define its control flow, such as repeating the blocks contained inside it forever, repeating the blocks contained inside for a set number of times, running the blocks inside if the Boolean condition is reported to be true, or running the blocks inside the if section or else section based on the Boolean value reported. The Switch C blocks are shaped to attach stacks above, below, or inside them.
Hat blocks: The Switch hat block is used to create a custom function similar to the hat block in My Blocks. However, it defines the function with the Python command in its text box. The Switch hat block is shaped to attach stack blocks below them, and run the attached stack of blocks when the function is called.
Great. Now we've gained a basic understanding of using different Switch blocks in VEXcode VR, and we will dive into each Switch Python command deeper in our future classes. Are you eager to use the Switch block in your project and get the first taste of Python programming? Be sure to stay tuned for our next lesson, where we'll use a Switch code block in an exciting challenge, Coral Reef Cleanup.
(upbeat music)
Welcome to today's lesson. In this lesson, we're going to explore how to use the Switch blocks in VEXcode VR and view the Python applications of various block codes in Switch. This is a fantastic way to start learning text-based programming to enhance your coding skills while still having loads of fun with the block-based approach.
Let's start by accessing the Switch mode blocks in VEXcode VR. Launch VEXcode VR from your browser. Select the Switch category. Under the Switch category, there are five types of Switch blocks with different shapes. Each Switch block includes at least one text box for displaying or entering the Python command. The Switch blocks follow the same shape conventions as other blocks we are familiar with.
Let's take a look at how each type of Switch block is used.
Stack blocks: The Stack blocks are the blocks that perform main commands. Instead of specifying a specific behavior like other Stack blocks, the Switch Stack block uses the Python command in its text box to define a specific behavior, such as moving the drivetrain for a given distance, turning the drivetrain for a given number of degrees, setting the position of the VR pen, et cetera. Switch stack blocks can be used for multiple lines of Python commands, adding flexibility to their use in programming. They are shaped to attach above or below other stack blocks.
Boolean blocks: Boolean blocks are the hexagonal blocks that return a condition as either true or false. In contrast to other Boolean blocks that define a condition directly, the Switch Boolean block utilizes a Python statement in its text box to determine the condition. The Python statement can be a sensor status function that returns a Boolean value, a comparison operation, a logical operation, et cetera. The Switch Boolean blocks are used with blocks that accept hexagonal Boolean blocks.
Reporter blocks: Reporter blocks are the oval blocks that report values in the form of numbers. Unlike other reporter blocks that specify the reported value directly, the Switch reporter block uses the Python statement in its text box to define the value to be returned. The Python statement can be a sensor status function that returns a number value, a variable, a mathematical operation, et cetera. The reporter blocks are used with blocks that accept oval reporter blocks.
C blocks: C blocks will loop the blocks within them or check if a condition is true or false. Rather than representing a fixed control flow structure as other C blocks do, the Switch C block uses the Python statement in its text box to define its control flow, such as repeating the blocks contained inside it forever, repeating the blocks contained inside for a set number of times, running the blocks inside if the Boolean condition is reported to be true, or running the blocks inside the if section or else section based on the Boolean value reported. The Switch C blocks are shaped to attach stacks above, below, or inside them.
Hat blocks: The Switch hat block is used to create a custom function similar to the hat block in My Blocks. However, it defines the function with the Python command in its text box. The Switch hat block is shaped to attach stack blocks below them, and run the attached stack of blocks when the function is called.
Great. Now we've gained a basic understanding of using different Switch blocks in VEXcode VR, and we will dive into each Switch Python command deeper in our future classes. Are you eager to use the Switch block in your project and get the first taste of Python programming? Be sure to stay tuned for our next lesson, where we'll use a Switch code block in an exciting challenge, Coral Reef Cleanup.
(upbeat music)
Share
Like this video? Share it with others!
Additional Resources
Like this video? Discuss it in the VEX Professional Learning Community.