功能#

新功能#

函数是用于执行某个操作的代码块。

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

如果函数没有任何要执行的代码,则应该在函数定义中包含一个传递。

# 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#

必须使用 VRThread 函数来调用脚本全局级别的函数。

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.

函数通常会按照调用的顺序执行。但是,如果一个函数等待,它会将执行权交给下一个函数,直到另一个函数执行完毕或等待完成时才继续执行。

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

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