我的积木#
我的块用于创建自定义块。
我的块用于创建可在整个项目中多次使用的块序列。
我的区块是使用制作区块按钮制作的。
我的块可以有多个参数 - 文本标签、数字变量和布尔变量 - 以便为您的自定义块添加更多功能。
要使用“我的块”,请将调用“我的块”附加到“帽子块”。当项目中调用“我的块”时,其中的堆栈将使用指定的参数值运行。
myBlock
定义 myBlock
注意:在 Playgrounds 中运行项目时,创建具有相同标签和变量的多个我的区块可能会导致错误。
在这个例子中,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
结束