我的积木#
介绍#
My Blocks is the equivalent to functions in Python. My Blocks group blocks into reusable, efficient sections of blocks designed to perform a specific task. My Blocks can be called multiple times within a program, making project organization easier, and helping to avoid repeated blocks.
定义 myBlock
myBlock
参数 |
描述 |
|---|---|
区块名称 |
A name you give to your My Block. |
参数 |
Optional. Variables that accept input values when the function is called, allowing data to be passed into the function. It can be a number or Boolean. |
定义和调用我的代码块#
我的积木#
如果“我的模块”不需要输入,则可以不带参数定义它。
定义 greeting
[Define a My Block to display a message.]
打印 [Hello!] ▶
当开始 :: hat events
[Call a My Block to display the message.]
greeting
我的带参数的块#
Parameters let you give a My Block the information it needs to work, such as how many times to complete a sequence of movements. For example, a My Block could use a number parameter to tell the robot how many steps to drive. This lets you use the same My Block in different ways depending on what values you give it.
定义 turns (number) :: custom
[Define a My Block with a parameter.]
驱动 [向前 v] (50) [毫米 v] ▶
[右 v] 转 (90) 度 ▶
当开始 :: hat events
[Call a My Block start turning.]
turns [4]