2021-01-19 09:20:52 +00:00
---
module: [kind=event] rednet_message
see: modem_message For raw modem messages sent outside of Rednet.
see: rednet.receive To wait for a Rednet message with an optional timeout and protocol filter.
---
2023-03-15 21:52:13 +00:00
<!--
SPDX-FileCopyrightText: 2021 The CC: Tweaked Developers
2023-03-28 09:23:28 +00:00
SPDX-License-Identifier: MPL-2.0
2023-03-15 21:52:13 +00:00
-->
2023-08-24 09:48:30 +00:00
The [`rednet_message`] event is fired when a message is sent over Rednet.
2021-01-19 09:20:52 +00:00
2023-08-24 09:48:30 +00:00
This event is usually handled by [`rednet.receive`], but it can also be pulled manually.
2021-01-19 09:20:52 +00:00
2023-08-24 09:48:30 +00:00
[`rednet_message`] events are sent by [`rednet.run`] in the top-level coroutine in response to [`modem_message`] events. A [`rednet_message`] event is always preceded by a [`modem_message`] event. They are generated inside CraftOS rather than being sent by the ComputerCraft machine.
2021-01-19 09:20:52 +00:00
## Return Values
2023-08-24 09:48:30 +00:00
1. [`string`]: The event name.
2. [`number`]: The ID of the sending computer.
3. [`any`]: The message sent.
4. < span class = "type" > [`string`]|[`nil`]</ span > : The protocol of the message, if provided.
2021-01-19 09:20:52 +00:00
## Example
Prints a message when one is sent:
```lua
while true do
local event, sender, message, protocol = os.pullEvent("rednet_message")
if protocol ~= nil then
print("Received message from " .. sender .. " with protocol " .. protocol .. " and message " .. tostring(message))
else
print("Received message from " .. sender .. " with message " .. tostring(message))
end
end
```