TL;DR
Add a way to register an a specific entity (or it's control behaviour) to raise an event when the signal input changes (and optionally passes some conditions ). Similar to how register_on_object_destroyed works. Something like:Code: Select all
---Lua psuodo declaration of function to register a specific entity for signal changed events.
---@param conditions DeciderCombinatorCondition[]?
---@return uint64 registeration number
function LuaEntity.register_on_signal_changed(filters)
-- ...
end
Code: Select all
---@class EventData.OnSignalChanged
---@uint64 registration_number
Example Usage
Code: Select all
script.on_event(defines.events.on_built_entity, function (event)
local registration_number = event.entity.register_on_signal_changed()
storage.entity_signal_listeners[registration_number] = event.entity
end)
script.on_event(defines.events.on_signal_changed, function (event)
local entity = storage.entity_signal_listeners[event.registration_number]
if not entity then return end -- We don't care about this event
game.print("Signal update with: "..entity)
end)
Why
Maybe this approach will not run into the same concerns other similar requests had about performance impact or too much events firing (for example 75678, 104311, 99990). The events will only ever fire for that small handful of entities that are registered. This could probably also be implemented in a way that doesn't increase the memory footprint of an entity.Other requests
Here is an alterative request by DaveMcW that could also be nice: 98542There also is another request that's very similar to mine if I read it correctly: 123158
