Page 1 of 1

What events does my mod listen to?

Posted: Tue May 24, 2022 6:49 pm
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.

Re: What events does my mod listen to?

Posted: Tue May 24, 2022 8:37 pm
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.

Re: What events does my mod listen to?

Posted: Wed May 25, 2022 5:35 am
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. :-)