New Function#

Functions are blocks of code used to perform an action.

Use the keyword def before your function name to define the function.

Include parentheses () enclosing optional parameters after the function name, followed by a colon: Multiple parameters should be separated by commas (parameter1, parameter2).

If there isn’t any code for the function to execute, a pass should be included in the function definition.

# Define the new function "draw_line".
def draw_line():
    drivetrain.drive_for(FORWARD, 400, MM)

def main():
    # Call the previously defined function "draw_line".


The VR Thread function must be used to call functions at the global level of the script.

You can take any function you have made previously, and pass it to vr_thread() at the global level. Calling at least one function inside of this is required to run a program. You do not need to do all function calls with vr_thread(), just ones that are at the global level.

If more than one vr_thread() call is made, the functions will execute in parallel.

The functions will, in general, execute in the order they are called. However, if a function waits, it will pass execution to the next function, and continue when the other function finishes, or when the other function also waits.

# Define the function "main".
def main():
    drivetrain.drive_for(FORWARD, 400, MM)

# Call VR thread for any previously defined functions.