Merge pull request #58 from thesabinelim/patch-1
Elaborate on onEvent documentation
This commit is contained in:
@@ -14,7 +14,7 @@ You can find a full list here: [CC:Tweaked](https://tweaked.cc/) (on the left si
|
|||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
* Add an onEvent event to your frame:
|
Add an onEvent event to your frame:
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
local basalt = require("basalt")
|
local basalt = require("basalt")
|
||||||
@@ -26,3 +26,23 @@ main:onEvent(function(event, side, channel, replyChannel, message, distance)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
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
|
||||||
|
<onEvent>
|
||||||
|
local eventType = event[2]
|
||||||
|
|
||||||
|
if (eventType == "modem_message") then
|
||||||
|
local message = event[6]
|
||||||
|
basalt.debug("Message received: " .. message)
|
||||||
|
end
|
||||||
|
</onEvent>
|
||||||
|
```
|
||||||
|
|
||||||
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user