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

Robot 1

    when screen [pressed v]
    [Code for Robot 1.]
    [Press the screen to send a message to Robot 2.]
    print [Robot 1] on screen ▶
    [Change the string to display a different message.]
    send message [Hello, Robot 2!]

Robot 2

    when started
    [Code for Robot 2.]
    [Display what 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 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

Robot 1

    when screen [pressed v]
    [Code for Robot 1.]
    [Continuously send the current heading to Robot 2.]
    print [Robot 1] on screen ▶
    forever
    send message [message] with data (heading in degrees)

Robot 2

    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 ▶

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

Robot 1

    when screen [pressed v] :: hat events
    [Code for Robot 1.]
    [Press the screen to send a message to Robot 2.]
    print [Robot 1] on screen ▶
    [Change the string to display a different message.]
    send message [Hello, Robot 2!]

Robot 2

    when started
    [Code for Robot 2.]
    [Display what 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 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

Robot 1

    when screen [pressed v] :: hat events
    [Code for Robot 1.]
    [Continuously send the current heading to Robot 2.]
    print [Robot 1] on screen ▶
    forever
    send message [message] with data (heading in degrees)

Robot 2

    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 ▶

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

Robot 1

    when screen [pressed v] :: hat events
    [Code for Robot 1.]
    [Press the screen to send a message to Robot 2.]
    print [Robot 1] on screen ▶
    [Change the string to display a different message.]
    send message [Hello, Robot 2!]

Robot 2

    when started
    [Code for Robot 2.]
    [Display what 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 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

Robot 1

    when screen [pressed v] :: hat events
    [Code for Robot 1.]
    [Continuously send the current heading to Robot 2.]
    print [Robot 1] on screen ▶
    forever
    send message [message] with data (heading in degrees)

Robot 2

    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 ▶

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

Robot 1

    when screen [pressed v] :: hat events
    [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
    [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? 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
    [Turn off one of the linked robots to see the message change.]
    forever
    clear screen
    print <is connected?> on screen ▶