pxt-calliope/libs/radio-broadcast/docs/reference/radio/on-received-message.md
Juri Wolf 77ed2ccfb1
V4 updates (#210)
* update pxt.json files

* Fix button event enums

fixes https://github.com/microsoft/pxt-calliope/issues/206

* Fix Safari CSS Rule for iOS app

fixes https://github.com/microsoft/pxt-calliope/issues/205

* aprove preffered repos

should fix https://github.com/microsoft/pxt-calliope/issues/167
2023-01-11 09:51:27 -08:00

1.0 KiB

on Received Message

Run part of a program when the @boardname@ receives a message over radio.

radio.onReceivedMessage(0, function() {})

Parameters

Examples

Example: Broadcasting heart or skull

Sends a heart message when A is pressed, skull when B is pressed. On the side, display heart or skull for the message.

enum RadioMessage {
    heart,
    skull
}
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), function () {
    radio.sendMessage(RadioMessage.heart)
})
input.onButtonEvent(Button.B, input.buttonEventValue(ButtonEvent.Click), function () {
    radio.sendMessage(RadioMessage.skull)
})
radio.onReceivedMessage(RadioMessage.heart, function () {
    basic.showIcon(IconNames.Heart)
})
radio.onReceivedMessage(RadioMessage.skull, function () {
    basic.showIcon(IconNames.Skull)
})

See also

send message,

radio-broadcast