Message#

Introduction#

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.

Note: For messages to be sent and received, both robots must be running projects that handle messaging at the same time.

Below is a list of all available blocks:

send message#

The send message block sends a string to the other linked robot.

    send message [message]

Parameters

Description

message

The string to send to the other linked robot.

Example

    when screen [pressed v] :: hat events
    [Press the screen to send a message to the other robot.]
    send message [message]
    when started :: hat events
    [Display when a message is received.]
    wait until <is message available?>
    print [Received!] on screen ▶

send message with data#

The send message with data block sends a string and a number to the other linked robot.

    send message [message] with data [0]

Parameters

Description

message

The value to send to the other linked robot. This must be a string.

data

A number to send to the other robot.

Example

    when screen [pressed v] :: hat events
    [Send the current heading to the other robot.]
    send message [message] with data (heading in degrees)
    when started :: hat events
    [Turn to match the other robot's heading.]
    forever
    if <is message available?> then
    get latest message with data
    turn to heading (latest data) degrees ▶

get latest message#

The get latest message block stores the most recent string received from the other linked robot.

    get latest message

Parameters

Description

This block has no parameters.

Example

    when started :: hat events
    [Display the received message.]
    wait until <is message available?>
    get latest message
    print (latest message) on screen ▶
    when screen [pressed v] :: hat events
    [Send "VEXcode!" to the other robot.]
    send message [VEXcode!]

get latest message with data#

The get latest message with data block stores the most recent string and number received from the other linked robot.

    get latest message with data

Parameters

Description

This block has no parameters.

Example

    when started :: hat events
    [Turn to match the other robot's heading.]
    forever
    if <is message available?> then
    get latest message with data
    turn to heading (latest data) degrees ▶
    when screen [pressed v] :: hat events
    [Send the current heading to the other robot.]
    send message [message] with data (heading in degrees)

latest message#

The latest message block returns the most recent stored string from the last use of the get latest message or get latest message with data block.

    (latest message)

Parameters

Description

This block has no parameters.

Example

    when started :: hat events
    [Display the received message.]
    wait until <is message available?>
    get latest message
    print (latest message) on screen ▶
    when screen [pressed v] :: hat events
    [Send "VEXcode!" to the other robot.]
    send message [VEXcode!]

latest data#

The latest data block returns the most recent stored number from the last use of the get latest message with data block.

    (latest data)

Parameters

Description

This block has no parameters.

Example

    when started :: hat events
    [Turn to match the other robot's heading.]
    forever
    if <is message available?> then
    get latest message with data
    turn to heading (latest data) degrees ▶
    when screen [pressed v] :: hat events
    [Send the current heading to the other robot.]
    send message [message] with data (heading in degrees)

is message available?#

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 yet in the current project.

    <is message available?>

Parameters

Description

This block has no parameters.

Example

    when started :: hat events
    [Display when a message is received.]
    wait until <is message available?>
    print [Message received!] on screen ▶
    when screen [pressed v] :: hat events
    [Press the screen to send a message to the other robot.]
    send message [message]

is connected?#

The is connected? block returns a Boolean indicating whether the robot is currently linked with another robot.

  • True - The robot is linked with another robot.

  • False - The robot is not linked with another robot.

    <is connected?>

Parameters

Description

This block has no parameters.

Example

    when started :: hat events
    [Turn off one of the linked robots to see the message change.]
    forever
    clear screen
    print <is connected?> on screen ▶