[0.13][API] index property in LuaCircuitNetwork.signals
Posted: Mon Jul 25, 2016 7:30 pm
It would be nice if the array returned by LuaCircuitNetwork.signals had a .index property (even if it is nearly meaningless) on each value. This is useful in mods when mirroring signals, as is desirable in all the new mods using surfaces - especially since I was told connecting poles across surfaces is probably map-corrupty, this seems to be the only alternative.
The current code to do this looks like this:
but if .signals had an index property already, it would collapse down to just
yielding significant performance improvements (as this is in an on_tick handler for each instance of the paired entities, and circuits actually need every tick).
The current code to do this looks like this:
Code: Select all
local rxNet = sconn.from.get_circuit_network(defines.wire_type.red) or sconn.from.get_circuit_network(defines.wire_type.green)
if rxNet and rxNet.valid then
local txControl = sconn.to.get_or_create_control_behavior()
local txSignals = rxNet.signals
local n = 1
for k,_ in pairs(txSignals) do
txSignals[k].index = n
n = n+1
end
txControl.parameters={parameters = txSignals}
end
Code: Select all
local rxNet = sconn.from.get_circuit_network(defines.wire_type.red) or sconn.from.get_circuit_network(defines.wire_type.green)
if rxNet and rxNet.valid then
sconn.to.get_or_create_control_behavior().parameters={parameters = rxNet.signals}
end