Why isn’t this event handler working?
Posted: Sat Oct 25, 2025 1:58 pm
(Before I start my questions, I’d like to mention that I’ve used C, C++, and some basic JavaScript, but I’m new to Lua through this modding project.)
For example, when I register an event handler as shown below, it seems that the handler is not being called.
When I directly assign the function like this, the handler is called.
To summarize what I’d like to ask:
1. Why is it that the event registration part and the event handler code cannot be separated as in the first example? Or is it simply a syntax mistake on my part?
2. Are event handlers only allowed to be global functions?
I also have some additional questions:
3. Is it absolutely forbidden to use storage at the time control.lua is loaded?
4. Can I assume that my mod is completely isolated from other mods? For example, do I not need to worry about name conflicts in things like Entity Names, Custom Events, or GUI Elements?
5. If script.on_event() is called multiple times, can the same handler be registered multiple times?
6. Is it valid to store and continuously use objects such as LuaPlayer obtained through Event Handlers?
7. I plan to add a util module, but Factorio already provides a built-in one. Is it okay to add my own functions to the default util module?
Thank you for taking the time to read my questions.
For example, when I register an event handler as shown below, it seems that the handler is not being called.
Code: Select all
local test_handler;
script.on_event("linox-ui-dialog-on-select", test_handler);
function test_handler(event)
--event handling
end
Code: Select all
script.on_event("linox-ui-dialog-on-select", function(event)
--event handling
end);
To summarize what I’d like to ask:
1. Why is it that the event registration part and the event handler code cannot be separated as in the first example? Or is it simply a syntax mistake on my part?
2. Are event handlers only allowed to be global functions?
I also have some additional questions:
3. Is it absolutely forbidden to use storage at the time control.lua is loaded?
4. Can I assume that my mod is completely isolated from other mods? For example, do I not need to worry about name conflicts in things like Entity Names, Custom Events, or GUI Elements?
5. If script.on_event() is called multiple times, can the same handler be registered multiple times?
6. Is it valid to store and continuously use objects such as LuaPlayer obtained through Event Handlers?
7. I plan to add a util module, but Factorio already provides a built-in one. Is it okay to add my own functions to the default util module?
Thank you for taking the time to read my questions.