mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 15:30:41 +09:00
Add on_server_startup event
Add startup event to the Clusterio module API which is raised at startup of a Factorio server. This is to server as a replacement for the on_init and on_configuration_changed events which cannot be used in modules. Adds clusterio_patch_number global from the patcher in order to implement this. This is a number that's incremented every time the save is patched.
This commit is contained in:
1 parent
b8fb73f863
commit
892c803496
6 files changed
+46
-9
No files matched your search
@@ -14,6 +14,7 @@ Contents
|
||||
- [event_handler interface](#event_handler-interface)
|
||||
- [Communicating with Clusterio](#communicating-with-clusterio)
|
||||
- [Clusterio Modules](#clusterio-modules)
|
||||
- [Clusterio Module API](#clusterio-module-api)
|
||||
- [Clusterio Plugins](#clusterio-plugins)
|
||||
|
||||
|
||||
@@ -188,6 +189,7 @@ structure:
|
||||
"name": "my_module",
|
||||
"version": "1.2.0",
|
||||
"dependencies": {
|
||||
"clusterio": "*",
|
||||
"foo": ">=0.4.2"
|
||||
},
|
||||
"require": ["bar.lua"],
|
||||
@@ -248,8 +250,21 @@ module.
|
||||
Because modules can be patched into an existing game you cannot rely on
|
||||
the `on_init` callback to be called in Clusterio Modules. Nor can you
|
||||
rely on the `on_configuration_changed` callback, as this is not called
|
||||
when level code changes. Instead you will have to initialize whatever
|
||||
global variable you need when you first use them.
|
||||
when level code changes. The `clusterio` module provides the custom
|
||||
`on_server_startup` event that can be used as a substitute, see the next
|
||||
section.
|
||||
|
||||
|
||||
### Clusterio Module API
|
||||
|
||||
There's a builtin clusterio module that provides some tools for getting
|
||||
instance info and communicating to plugins, script events to listen for
|
||||
and a Factorio remote call API. The available interfaces is documented
|
||||
in [modules/clusterio/api.lua](modules/clusterio/api.lua). To use this
|
||||
API from another module, require it using something along the lines of
|
||||
`local clusterio_api = require("modules/clusterio/api")`. Make sure to
|
||||
add `clusterio` as a dependency in your module.json if you use the
|
||||
dependency entry in it.
|
||||
|
||||
|
||||
Clusterio Plugins
|
||||
|
||||
@@ -190,7 +190,7 @@ And then in the module for the plugin:
|
||||
local clusterio_api = require('modules/clusterio/api')
|
||||
|
||||
-- inside some event handler
|
||||
clusterio_api.send('my_plugin_foo', { data = 123 })
|
||||
clusterio_api.send_json('my_plugin_foo', { data = 123 })
|
||||
|
||||
It's recommended to either use the plugin name as the channel name or to
|
||||
prefix the channel name with the name of the plugin if you need multiple
|
||||
|
||||
Reference in new issue
Block a user