信息#

介绍#

两个 VEX AIM 编码机器人可以连接,以便在项目期间进行通信。使用消息积木,机器人可以发送和接收信息以协调其动作。

**注意:**为了发送和接收消息,两个机器人必须同时运行处理消息的项目。

以下是所有可用块的列表:

发送消息#

发送消息块向另一个链接的机器人发送一个字符串。

发送消息 [message]

参数

描述

信息

发送给其他链接机器人的字符串。

例子

Robot 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!]

Robot 2

当开始
[Code for Robot 2.]
[Display what message Robot 1 sends.]
在屏幕上打印 [Robot 2]▶
在屏幕上设定光标至下一行
等到 <有消息吗?>
获取最新消息
在屏幕上打印 (最新消息)▶

发送带有数据的消息#

发送带有数据的消息块向另一个链接的机器人发送一个字符串和一个数字。

发送带有数据 [message]消息 [0]

参数

描述

信息

发送给其他关联机器人的值。该值必须是字符串。

数据

发送给另一个机器人的数字。

例子

Robot 1

当屏幕 [pressed v]
[Code for Robot 1.]
[Continuously send the current heading to Robot 2.]
在屏幕上打印 [Robot 1]▶
永久循环
发送带有数据 [message]消息 (归位角度值)

Robot 2

当开始
[Code for Robot 2.]
[Turn to match Robot 1's heading.]
在屏幕上打印 [Robot 2]▶
永久循环
如果 <有消息吗?> 那么
获取带有数据的最新消息
归位至 (最新数据) 度 ▶

获取最新消息#

获取最新消息块存储从其他链接机器人接收到的最新字符串。

获取最新消息

参数

描述

该块没有参数。

例子

Robot 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!]

Robot 2

当开始
[Code for Robot 2.]
[Display what message Robot 1 sends.]
在屏幕上打印 [Robot 2]▶
在屏幕上设定光标至下一行
等到 <有消息吗?>
获取最新消息
在屏幕上打印 (最新消息)▶

获取带有数据的最新消息#

获取带有数据的最新消息块存储从其他链接机器人接收到的最新字符串和数字。

获取带有数据的最新消息

参数

描述

该块没有参数。

例子

Robot 1

当屏幕 [pressed v] :: hat events
[Code for Robot 1.]
[Continuously send the current heading to Robot 2.]
在屏幕上打印 [Robot 1]▶
永久循环
发送带有数据 [message]消息 (归位角度值)

Robot 2

当开始
[Code for Robot 2.]
[Turn to match Robot 1's heading.]
在屏幕上打印 [Robot 2]▶
永久循环
如果 <有消息吗?> 那么
获取带有数据的最新消息
归位至 (最新数据) 度 ▶

最新消息#

最新消息块返回上次使用获取最新消息获取带有数据的最新消息 块时存储的最新字符串。

(最新消息)

参数

描述

该块没有参数。

例子

Robot 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!]

Robot 2

当开始
[Code for Robot 2.]
[Display what message Robot 1 sends.]
在屏幕上打印 [Robot 2]▶
在屏幕上设定光标至下一行
等到 <有消息吗?>
获取最新消息
在屏幕上打印 (最新消息)▶

最新数据#

最新数据块返回上次使用获取带有数据的最新消息 块时存储的最新数字。

(最新数据)

参数

描述

该块没有参数。

例子

Robot 1

当屏幕 [pressed v] :: hat events
[Code for Robot 1.]
[Continuously send the current heading to Robot 2.]
在屏幕上打印 [Robot 1]▶
永久循环
发送带有数据 [message]消息 (归位角度值)

Robot 2

当开始
[Code for Robot 2.]
[Turn to match Robot 1's heading.]
在屏幕上打印 [Robot 2]▶
永久循环
如果 <有消息吗?> 那么
获取带有数据的最新消息
归位至 (最新数据) 度 ▶

有消息吗?#

消息可用吗? 块返回一个布尔值,指示其他链接机器人是否曾经在当前项目中使用过 发送消息发送带有数据的消息 块。

<有消息吗?>

参数

描述

该块没有参数。

例子

Robot 1

当屏幕 [pressed v] :: hat events
[Code for Robot 1.]
[Press the screen to send a message to Robot 2.]
在屏幕上打印 [Robot 1]▶
发送消息 [message]

Robot 2

当开始
[Code for Robot 2.]
[Display a message when Robot 1 sends a message.]
在屏幕上打印 [Robot 2]▶
在屏幕上设定光标至下一行
等到 <有消息吗?>
在屏幕上打印 [Received!]▶

已连接?#

**是否连接?**块返回一个布尔值,指示机器人当前是否与另一个机器人相连。

  • 真 - 该机器人与另一个机器人相连。

  • 错误 - 机器人未与其他机器人连接。

<已连接?>

参数

描述

该块没有参数。

例子

当开始
[Turn off one of the linked robots to see the message change.]
永久循环
清屏
在屏幕上打印 <已连接?>▶