From e3de424f42e64e34a9a9ac3248f5c36fe96269cd Mon Sep 17 00:00:00 2001 From: Sabine Lim Date: Mon, 8 May 2023 01:57:14 +1000 Subject: [PATCH 1/2] Elaborate on onEvent documentation --- docs/objects/Object/onEvent.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/objects/Object/onEvent.md b/docs/objects/Object/onEvent.md index fd825af..f90d1a9 100644 --- a/docs/objects/Object/onEvent.md +++ b/docs/objects/Object/onEvent.md @@ -14,7 +14,7 @@ You can find a full list here: [CC:Tweaked](https://tweaked.cc/) (on the left si ### Usage -* Add an onEvent event to your frame: +Add an onEvent event to your frame: ```lua local basalt = require("basalt") @@ -26,3 +26,22 @@ main:onEvent(function(event, side, channel, replyChannel, message, distance) end end) ``` + +The parameters passed to this function are the same as those returned by `os.pullEvent()`. See [here](https://computercraft.info/wiki/Os.pullEvent) for more info. + +Alternatively, you can add an onEvent event to an XML layout: + +```xml + + local eventType = event[3] + local message = event[7] + if (eventType == "modem_message") then + basalt.debug("Message received: " .. tostring(message)) + end + +``` + +In this case, the event table indices correspond to: +* 1: The Object where this event is being handled +* 2: A string representing the Basalt event type. This will always just be the string `"other_event"` +* 3 onwards: the `os.pullEvent()` parameters -- 2.49.1 From 2e65d14538902fdba217d5116fec40c6dafdaa93 Mon Sep 17 00:00:00 2001 From: Sabine Lim Date: Mon, 8 May 2023 02:04:16 +1000 Subject: [PATCH 2/2] Update onEvent.md --- docs/objects/Object/onEvent.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/objects/Object/onEvent.md b/docs/objects/Object/onEvent.md index f90d1a9..875472a 100644 --- a/docs/objects/Object/onEvent.md +++ b/docs/objects/Object/onEvent.md @@ -27,16 +27,17 @@ main:onEvent(function(event, side, channel, replyChannel, message, distance) end) ``` -The parameters passed to this function are the same as those returned by `os.pullEvent()`. See [here](https://computercraft.info/wiki/Os.pullEvent) for more info. +The parameters passed to this function are the same as those returned by `os.pullEvent()`. See [here](https://tweaked.cc/module/os.html#v:pullEvent) for more info. Alternatively, you can add an onEvent event to an XML layout: ```xml - local eventType = event[3] - local message = event[7] + local eventType = event[2] + if (eventType == "modem_message") then - basalt.debug("Message received: " .. tostring(message)) + local message = event[6] + basalt.debug("Message received: " .. message) end ``` -- 2.49.1