Message#

Introduction#

Two VEX AIM Coding Robots can be linked so they can communicate during a project. Message blocks let one robot send a message to the other robot. A message can include text by itself, or text with a number.

Received messages are stored in a first-in, first-out (FIFO) queue. This means the first message received is the first message that will be read.

Use a get latest message block to store the next received message. Then use the latest message reporter block to read the stored text. If the message also includes a number, use get latest message with data to store both values, then use latest message and latest data to read them.

Note: For messages to be sent and received, both robots must be linked and both robots must be running projects that use Message blocks.

Below is a list of all blocks:

Values — Read message information or check message and connection status.

Actions — Send or store received messages.

Values#

latest message#

The latest message reporter block reports the most recently stored text message. This block does not get a new message by itself. Use get latest message or get latest message with data first, then use latest message to display the stored text or use it in another block.

latest message reporter block#
    (latest message)

Parameters

Description

This block has no parameters.

Example

Robot 1

When the screen is pressed, sends a message to Robot 2.#
    when screen [pressed v]
    [Code for Robot 1.]
    [Press the screen to send a message to Robot 2.]
    print [Robot 1] on screen ▶
    send message [Hello, Robot 2!]

Robot 2

When started, displays the latest stored message.#
    when started
    [Code for Robot 2.]
    [Display the message Robot 1 sends.]
    print [Robot 2] on screen ▶
    set cursor to next row on screen
    wait until <is message available?>
    get latest message
    print (latest message) on screen ▶

latest data#

The latest data reporter block reports the most recently stored number from a message that included data. This block does not get a new number by itself. Use get latest message with data first, then use latest data in another block, such as a drive distance, turn heading, or speed value.

latest data reporter block#
    (latest data)

Parameters

Description

This block has no parameters.

Example

Robot 1

When started, continuously sends Robot 1’s heading to Robot 2.#
    when started
    [Code for Robot 1.]
    [Continuously send the current heading to Robot 2.]
    print [Robot 1] on screen ▶
    forever
        send message [heading] with data (heading in degrees)
    end

Robot 2

When started, turns to match the latest stored data.#
    when started
    [Code for Robot 2.]
    [Turn to match Robot 1's heading.]
    print [Robot 2] on screen ▶
    forever
        if <is message available?> then
            get latest message with data
            turn to heading (latest data) degrees ▶
        end
    end

is message available?#

The is message available? Boolean block reports whether a message is waiting in the message queue. Use this block before get latest message or get latest message with data so the receiving robot only tries to store a message after one has arrived.

  • True — There is a message available to be read.

  • False — There are no messages available to be read.

is message available? Boolean block#
    <is message available?>

Parameters

Description

This block has no parameters.

Example

Robot 1

When the screen is pressed, sends a message to Robot 2.#
    when screen [pressed v]
    [Code for Robot 1.]
    [Press the screen to send a message to Robot 2.]
    print [Robot 1] on screen ▶
    send message [message]

Robot 2

When started, displays a message when Robot 1 sends a message.#
    when started
    [Code for Robot 2.]
    [Display a message when Robot 1 sends a message.]
    print [Robot 2] on screen ▶
    set cursor to next row on screen
    wait until <is message available?>
    print [Received!] on screen ▶

is connected?#

The is connected? Boolean block reports whether the robot is linked with another robot. Use this block before sending or waiting for messages if the project needs to check that the robot-to-robot connection is ready.

  • True — The robot is linked with another robot.

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

is connected? Boolean block#
    <is connected?>

Parameters

Description

This block has no parameters.

Example

When started, displays whether the robot is connected.#
    when started
    [Turn off one of the linked robots to see the message change.]
    forever
        clear screen
        print <is connected?> on screen ▶
    end

linked robot name#

The linked robot name reporter block reports the name of the linked robot. Use this block to show which robot is connected before sending or receiving messages. If no robot is linked, this block reports None.

linked robot name reporter block#
    (linked robot name)

Parameters

Description

This block has no parameters.

Example

When started, displays the name of the linked robot.#
    when started
    [Display the name of the robot that is linked.]
    print (linked robot name) on screen ▶

Actions#

send message#

The send message stack block sends text to the linked robot. Use this block on one robot when the other robot needs to receive a command, signal, or short piece of information. On the receiving robot, use is message available? to check that a message has arrived, then use get latest message before reading it with latest message.

send message stack block#
    send message [message]

Parameter

Description

message

The text to send to the linked robot.

Example

Robot 1

When the screen is pressed, sends a message to Robot 2.#
    when screen [pressed v]
    [Code for Robot 1.]
    [Press the screen to send a message to Robot 2.]
    print [Robot 1] on screen ▶
    send message [Hello, Robot 2!]

Robot 2

When started, displays the message sent by Robot 1.#
    when started
    [Code for Robot 2.]
    [Display the message Robot 1 sends.]
    print [Robot 2] on screen ▶
    set cursor to next row on screen
    wait until <is message available?>
    get latest message
    print (latest message) on screen ▶

send message with data#

The send message with data stack block sends text and a number to the linked robot. Use this block when the message needs a label and a number, such as sending heading with the robot’s current heading value. On the receiving robot, use is message available? to check that a message has arrived, then use get latest message with data before reading the text with latest message and the number with latest data.

send message with data stack block#
    send message [message] with data [0]

Parameter

Description

message

The text to send to the linked robot.

data

The number to send with the message.

Example

Robot 1

When started, continuously sends Robot 1’s heading to Robot 2.#
    when started
    [Code for Robot 1.]
    [Continuously send the current heading to Robot 2.]
    print [Robot 1] on screen ▶
    forever
        send message [heading] with data (heading in degrees)
    end

Robot 2

When started, turns to match the heading sent by Robot 1.#
    when started
    [Code for Robot 2.]
    [Turn to match Robot 1's heading.]
    print [Robot 2] on screen ▶
    forever
        if <is message available?> then
            get latest message with data
            turn to heading (latest data) degrees ▶
        end
    end

get latest message#

The get latest message stack block takes the next received text message from the message queue and stores it so the project can use it. Use this block after is message available? reports True and before using latest message. This helps the receiving robot save the message before trying to display it, compare it, or use it in another block.

Use send message on the other robot to send a text-only message.

get latest message stack block#
    get latest message

Parameters

Description

This block has no parameters.

Example

Robot 1

When the screen is pressed, sends a message to Robot 2.#
    when screen [pressed v]
    [Code for Robot 1.]
    [Press the screen to send a message to Robot 2.]
    print [Robot 1] on screen ▶
    send message [Hello, Robot 2!]

Robot 2

When started, stores and displays the message sent by Robot 1.#
    when started
    [Code for Robot 2.]
    [Display the message Robot 1 sends.]
    print [Robot 2] on screen ▶
    set cursor to next row on screen
    wait until <is message available?>
    get latest message
    print (latest message) on screen ▶

get latest message with data#

The get latest message with data stack block takes the next received message from the message queue and stores both parts of it: the text message and the number sent with it. Use this block after is message available? reports True and before using latest message or latest data. This helps the receiving robot save both values before using them, such as turning to a heading that another robot sent.

Use send message with data on the other robot to send the text and number together.

get latest message with data stack block#
    get latest message with data

Parameters

Description

This block has no parameters.

Example

Robot 1

When started, continuously sends Robot 1’s heading to Robot 2.#
    when started
    [Code for Robot 1.]
    [Continuously send the current heading to Robot 2.]
    print [Robot 1] on screen ▶
    forever
        send message [heading] with data (heading in degrees)
    end

Robot 2

When started, stores the message data and turns to match Robot 1’s heading.#
    when started
    [Code for Robot 2.]
    [Turn to match Robot 1's heading.]
    print [Robot 2] on screen ▶
    forever
        if <is message available?> then
            get latest message with data
            turn to heading (latest data) degrees ▶
        end
    end