In addition to separate device and stage programming, mBlock 5 also supports the interaction between devices and sprites. By using the following broadcast message blocks, you can enable a device to interact with a sprite, which allows you to have more fun with programming.

Enable a Device to Interact with a Sprite - 图1

In the programs described in previous sections, we have created a bee and added a sound and costume for it, and programmed Halocode.

Now, let’s try to enable Halocode to interact with the bee: when you press the blue button on Halocode, the bee on the stage moves.

Program the device

(1) Drag the Events block when button is pressed to the Scripts area.
image.png
(2) Drag the Events block broadcast ( ) to the Scripts area.

Enable a Device to Interact with a Sprite - 图3

(3) Create a new message. You can set a name for the new message to help identify it. In this example, let’s name it move.
image.png
image.png

Program the sprite

(1) Continue to compile the program described in “Add Sounds and Costumes“. Drag when green flag clicked back to the Blocks area to delete it.

Enable a Device to Interact with a Sprite - 图6

(2) Drag the Events block when I receive ( ) to the Scripts area and select the message move.

Enable a Device to Interact with a Sprite - 图7

(3) Press the blue button on Halocode and see what happens.

:::info Note: For more details about how to enable devices to interact with sprites, see Interact with Sprites . :::