Funciones#

Nueva función#

Las funciones son bloques de código que se utilizan para realizar una acción.

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

Si no hay ningún código para que la función se ejecute, se debe incluir un pase en la definición de la función.

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

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

vr_thread#

La función VR Thread debe usarse para llamar funciones a nivel global del 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.

En general, las funciones se ejecutan en el orden en que se llaman. Sin embargo, si una función espera, pasará la ejecución a la siguiente función y continuará cuando la otra termine o cuando esta también espere.

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

# Call VR thread for any previously defined functions.
vr_thread(main)