I've had a look through the code and the below section looks odd to me.
1: net_cache is a global lua variable, but not a global mod variable. It appears to be used as a lookup table, but isn't being stored in the mods state.
2: There is a global lua variable called "last_update" which seems to be called, but never set. Is this meant to be the same as the later usage of "ent_cache.last_update" in the function?
-- Cache the circuit networks to speed up performance
function update_net_cache(ent)
if not net_cache then
net_cache = {}
end
local ent_cache = net_cache[ent.unit_number]
if not ent_cache then
ent_cache = {last_update=-1}
net_cache[ent.unit_number] = ent_cache
end
-- Get the circuit networks at most once per tick per entity
if game.tick > ent_cache.last_update then
if not ent_cache.red_network or not ent_cache.red_network.valid then
ent_cache.red_network = ent.get_circuit_network(defines.wire_type.red)
end
if not ent_cache.green_network or not ent_cache.green_network.valid then
ent_cache.green_network = ent.get_circuit_network(defines.wire_type.green)
end
ent_cache.last_update = game.tick
end
return ent_cache;
end