What events does my mod listen to?

Place to get help with not working mods / modding interface.
Post Reply
Pi-C
Smart Inserter
Smart Inserter
Posts: 1639
Joined: Sun Oct 14, 2018 8:13 am
Contact:

What events does my mod listen to?

Post by Pi-C »

Is there a way to find out what events my mod is listening to at any given time? It could be useful for debugging, especially when event handlers are added in response to other events.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

robot256
Filter Inserter
Filter Inserter
Posts: 594
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: What events does my mod listen to?

Post by robot256 »

You can run https://lua-api.factorio.com/latest/Lua ... nt_handler on every event ID. Not sure how to know what range to use given custom events.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1639
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: What events does my mod listen to?

Post by Pi-C »

robot256 wrote:
Tue May 24, 2022 8:37 pm
You can run https://lua-api.factorio.com/latest/Lua ... nt_handler on every event ID.
Thanks, forgot about that one! It's a bit cumbersome, but should do.
Not sure how to know what range to use given custom events.
That wouldn't be a problem. I already have a reverse look-up list of defines.events, to which I've added on_init, on_configuration_changed, and on_load as well as the custom events from other mods that I listen to, so I can have markers like this in the log file:

Code: Select all

====================================================================================================
Entered event script for on_player_driving_changed_state
Event data: tick = 13173, player_index = 1, entity = car "crawler" (32)
(@__GCKI__/scripts/event_handlers.lua: 912)
====================================================================================================
It shouldn't be too hard to add a command that outputs/logs the events with a handler other than nil. The overhead for running get_event_handler almost 200 times in a row can be ignored as the command would only exist in debugging mode. :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Post Reply

Return to “Modding help”