mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-11 15:04:52 +09:00
Use entrypoint functions in the UDP docs examples
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0a6f614074
commit
857102956a
1 file changed
+9
-8
@@ -499,23 +499,24 @@ clusterio_api.send_udp("my_plugin_foo", "123")
|
||||
```
|
||||
|
||||
```js
|
||||
async init() {
|
||||
this.instance.server.handleUdp("my_plugin_foo", async data => {
|
||||
this.logger.info(`got ${data.toString()}`);
|
||||
export default async function(context) {
|
||||
const { instance, logger } = context;
|
||||
instance.server.handleUdp("my_plugin_foo", async data => {
|
||||
logger.info(`got ${data.toString()}`);
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
Like `handle` for `send_json`, `handleUdp` logs errors thrown by the handler.
|
||||
Use `this.instance.server.on("udp-my_plugin_foo", ...)` for custom error handling.
|
||||
Use `instance.server.on("udp-my_plugin_foo", ...)` for custom error handling.
|
||||
|
||||
Data into Factorio is sent with the `sendUdp` method on the plugin object and delivered in-game as `defines.events.on_udp_packet_received` events with the packet in `event.payload`.
|
||||
Data into Factorio is sent with the `sendUdp` method on the instance and delivered in-game as `defines.events.on_udp_packet_received` events with the packet in `event.payload`.
|
||||
The Clusterio module polls for received packets every tick, all modules and mods receive every packet so make sure the payload identifies your plugin.
|
||||
|
||||
```js
|
||||
async onStart() {
|
||||
await this.sendUdp("my_plugin_foo:123");
|
||||
}
|
||||
instance.hooks.start.attach(plugin.name, async () => {
|
||||
await instance.sendUdp("my_plugin_foo:123");
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user