我的指令块#

简介#

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.

定义和调用我的指令块#

我的指令块#

If a My Block does not require input, you can define it without parameters.

启动时,调用名为“greeting”的自定义块在屏幕上打印“Hello!”。#
定义 greeting
[Define a My Block to display a message]
print [Hello!] on screen ▶

when started
[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 far to drive. This lets you use the same My Block in different ways depending on what values you give it.

启动后,调用自定义块“named_greeting”,并传入一个参数。它会在屏幕上打印“Hello”,后面跟着指定的名字。#
定义 named_greeting (name)
[Define a My Block with a parameter]
print [Hello, ] on screen ▶
print (name) on screen ▶

when started
[Call a My Block to display the message]
named_greeting [Stranger]