我的积木#

“我的块” 允许您创建自定义的块序列,这些块可在整个项目中多次使用。有关如何使用它们的更多信息,请阅读在 VEXcode V5 中使用“我的块”

我的区块是使用制作区块按钮制作的。

一个带有圆角和浅灰色边框的矩形按钮,以粗体灰色文字标有“制作区块”,位于按钮中央。

我的块可以有多个参数 - 文本标签、数字变量和布尔变量 - 以便为您的自定义块添加更多功能。

myBlock

定义 myBlock

要使用“我的块”,请将调用“我的块”附加到“帽子块”。当项目中调用“我的块”时,其中的堆栈将使用指定的参数值运行。

在这个例子中,My Block 用于定义正方形的一条边。然后调用 4 次 My Block 来绘制正方形的所有四条边,最终完成形状。

定义 make a square
[Make the sides of the square 500mm.]
驱动 [向前 v] (500) [毫米 v] ▶
[Turn right 90 degrees to make it a square.]
[右 v] 转 (90) 度 ▶



当开始 :: hat events
重复 (4)
[Make 4 sides to complete a square.]
make a square
结束

我的方块 也可以自定义参数。在本例中,正方形边长可以调整,并在 我的方块 中更改。

定义 make a [sideLength] square
[Drive forward for what the sideLength is set to in mm.]
驱动 [向前 v] (sideLength) [毫米 v] ▶
[Turn right 90 degrees to make it a square.]
[右 v] 转 (90) 度 ▶



当开始 :: hat events
重复 (4)
[Type in the length of the square's sides.]
make a (500) square
结束