Add subscriptions and luacheck

This commit is contained in:
Cooldude2606 committed 2024-02-17 03:11:54 +00:00
1 parent 58231cc02c
commit f392b258f7
15 files changed
+3644 -39

No files matched your search

@@ -1,18 +1,40 @@
local clusterio_api = require("modules/clusterio/api")
--- Top level module table, contains event handlers and public methods
local MyModule = {
events = {},
on_nth_tick = {},
}
--- global is 'synced' between players, you should use your plugin name to avoid conflicts
-- setupGlobalData should either be removed or called during clusterio_api.events.on_server_startup
local globalData = {}
local function setupGlobalData()
if global["// plugin_name //"] == nil then
global["// plugin_name //"] = {
-- starting values go here
}
end
globalData = global["// plugin_name //"]
end
--- Public methods should be available though your top level module table
function MyModule.foo()
game.print("foo")
end
--- Private methods should be local to the file, this will prevent others from calling it
local function bar()
game.print("bar")
end
--- Clusterio provides a few custom events, on_server_startup is the most useful and should be used in place of on_load
MyModule.events[clusterio_api.events.on_server_startup] = function(event)
setupGlobalData()
game.print(game.table_to_json(event))
end
--- Factorio events are accessible through defines.events, you can have one handler per event per module
MyModule.events[defines.events.on_player_crafted_item] = function(event)
game.print(game.table_to_json(event))// [instance] //
clusterio_api.send_json("// plugin_name //-plugin_example_ipc", {
@@ -20,8 +42,11 @@ MyModule.events[defines.events.on_player_crafted_item] = function(event)
})// [] //
end
--- Nth tick is a special case that requires its own table, the index represents the time period between calls in ticks
MyModule.on_nth_tick[300] = function()
game.print(game.tick)
bar()
end
--- Always return the top level module table from control, this is how clusterio will access your event handlers
return MyModule