信息#
介绍#
Two VEX AIM Coding Robots can be linked so they communicate during a project. Using Message blocks, the robots can send and receive information to coordinate their actions.
Messages are stored in a first-in, first-out (FIFO) queue. The first message received is processed first, even if newer messages are available.
**注意:**为了发送和接收消息,两个机器人必须同时运行处理消息的项目。
Below is a list of all blocks:
send message — Sends a string to the other linked robot.
send message with data — Sends a string and a number to the other linked robot.
get latest message — Stores the most recent string received.
get latest message with data — Stores the most recent string and number received.
latest message — Returns the most recent stored string.
latest data — Returns the most recent stored number.
is message available? — Returns a Boolean indicating whether the other linked robot has ever sent a message.
is connected? — Returns a Boolean indicating whether the robot is linked with another robot.
linked robot name — Returns a string with the name of the linked robot.
发送消息#
发送消息块向另一个链接的机器人发送一个字符串。
发送消息 [message]
参数 |
描述 |
|---|---|
信息 |
发送给其他链接机器人的字符串。 |
例子
机器人 1
当屏幕 [pressed v]
[Code for Robot 1.]
[Press the screen to send a message to Robot 2.]
在屏幕上打印 [Robot 1]▶
[Change the string to display a different message.]
发送消息 [Hello, Robot 2!]
机器人 2
当开始
[Code for Robot 2.]
[Display what message Robot 1 sends.]
在屏幕上打印 [Robot 2]▶
在屏幕上设定光标至下一行
等到 <有消息吗?>
获取最新消息
在屏幕上打印 (最新消息)▶
发送带有数据的消息#
发送带有数据的消息块向另一个链接的机器人发送一个字符串和一个数字。
发送带有数据 [0]消息 [message]
参数 |
描述 |
|---|---|
信息 |
发送给其他关联机器人的值。该值必须是字符串。 |
数据 |
发送给另一个机器人的数字。 |
例子
机器人 1
当屏幕 [pressed v]
[Code for Robot 1.]
[Continuously send the current heading to Robot 2.]
在屏幕上打印 [Robot 1]▶
永久循环
发送带有数据 (归位角度值)消息 [message]
机器人 2
当开始
[Code for Robot 2.]
[Turn to match Robot 1's heading.]
在屏幕上打印 [Robot 2]▶
永久循环
如果 <有消息吗?> 那么
获取带有数据的最新消息
归位至 (最新数据) 度 ▶
获取最新消息#
获取最新消息块存储从其他链接机器人接收到的最新字符串。
获取最新消息
参数 |
描述 |
|---|---|
该块没有参数。 |
例子
机器人 1
当屏幕 [pressed v] :: hat events
[Code for Robot 1.]
[Press the screen to send a message to Robot 2.]
在屏幕上打印 [Robot 1]▶
[Change the string to display a different message.]
发送消息 [Hello, Robot 2!]
机器人 2
当开始
[Code for Robot 2.]
[Display what message Robot 1 sends.]
在屏幕上打印 [Robot 2]▶
在屏幕上设定光标至下一行
等到 <有消息吗?>
获取最新消息
在屏幕上打印 (最新消息)▶
获取带有数据的最新消息#
获取带有数据的最新消息块存储从其他链接机器人接收到的最新字符串和数字。
获取带有数据的最新消息
参数 |
描述 |
|---|---|
该块没有参数。 |
例子
机器人 1
当屏幕 [pressed v] :: hat events
[Code for Robot 1.]
[Continuously send the current heading to Robot 2.]
在屏幕上打印 [Robot 1]▶
永久循环
发送带有数据 (归位角度值)消息 [message]
机器人 2
当开始
[Code for Robot 2.]
[Turn to match Robot 1's heading.]
在屏幕上打印 [Robot 2]▶
永久循环
如果 <有消息吗?> 那么
获取带有数据的最新消息
归位至 (最新数据) 度 ▶
最新消息#
最新消息块返回上次使用获取最新消息 或获取带有数据的最新消息 块时存储的最新字符串。
(最新消息)
参数 |
描述 |
|---|---|
该块没有参数。 |
例子
机器人 1
当屏幕 [pressed v] :: hat events
[Code for Robot 1.]
[Press the screen to send a message to Robot 2.]
在屏幕上打印 [Robot 1]▶
[Change the string to display a different message.]
发送消息 [Hello, Robot 2!]
机器人 2
当开始
[Code for Robot 2.]
[Display what message Robot 1 sends.]
在屏幕上打印 [Robot 2]▶
在屏幕上设定光标至下一行
等到 <有消息吗?>
获取最新消息
在屏幕上打印 (最新消息)▶
最新数据#
最新数据块返回上次使用获取带有数据的最新消息 块时存储的最新数字。
(最新数据)
参数 |
描述 |
|---|---|
该块没有参数。 |
例子
机器人 1
当屏幕 [pressed v] :: hat events
[Code for Robot 1.]
[Continuously send the current heading to Robot 2.]
在屏幕上打印 [Robot 1]▶
永久循环
发送带有数据 (归位角度值)消息 [message]
机器人 2
当开始
[Code for Robot 2.]
[Turn to match Robot 1's heading.]
在屏幕上打印 [Robot 2]▶
永久循环
如果 <有消息吗?> 那么
获取带有数据的最新消息
归位至 (最新数据) 度 ▶
有消息吗?#
The is message available? block returns a Boolean indicating whether the other linked robot has ever used the send message or send message with data block.
True — The send message or send message with data block has been used by the other linked robot in the current project.
False — The send message or send message with data block has never been used by the other linked robot in the current project.
<有消息吗?>
参数 |
描述 |
|---|---|
该块没有参数。 |
例子
机器人 1
当屏幕 [pressed v] :: hat events
[Code for Robot 1.]
[Press the screen to send a message to Robot 2.]
在屏幕上打印 [Robot 1]▶
发送消息 [message]
机器人 2
当开始
[Code for Robot 2.]
[Display a message when Robot 1 sends a message.]
在屏幕上打印 [Robot 2]▶
在屏幕上设定光标至下一行
等到 <有消息吗?>
在屏幕上打印 [Received!]▶
已连接?#
**是否连接?**块返回一个布尔值,指示机器人当前是否与另一个机器人相连。
True — The robot is linked with another robot.
False — The robot is not linked with another robot.
<已连接?>
参数 |
描述 |
|---|---|
该块没有参数。 |
例子
当开始
[Turn off one of the linked robots to see the message change.]
永久循环
清屏
在屏幕上打印 <已连接?>▶
链接机器人名称#
“链接机器人名称”模块返回一个字符串,其中包含已链接机器人的名称。如果没有链接任何机器人,则返回“None”。
(linked robot name)
参数 |
描述 |
|---|---|
该块没有参数。 |
例子
当开始
[Display the name of the robot that's linked.]
在屏幕上打印 (linked robot name)▶