Multi Circuit Repeater


Wireless Circuit Networks, per channel. https://buymeacoffee.com/mallyhubz

Content
a month ago
2.0
392
Circuit network

b Adding repeaters breaks connections on existing channels

23 days ago

Bug: Adding repeaters to a new channel breaks connections on existing channels

I found bug related to how the mod rebuilds wire mesh connections between repeaters. When you assign repeaters to a new channel, any repeaters already connected on other channels lose their connections and get reassigned to different circuit numbers.

Steps to reproduce:
1. Place two repeaters and assign them both to channel "Foo". Connect circuit wires — both ends share the same circuit network number (e.g. 1829).
2. Place two more repeaters and assign them to a new channel "Bar".
3. The "Foo" repeaters are now on mismatched circuit numbers (e.g. 1829 and 1831) and are no longer connected to each other.

You can temporarily restore a broken channel by opening its renamer and committing the same name without changing it, but this just breaks the other channel in the process.

Root cause:

The problem is in ProcessFullLinkMesh. Every time a channel assignment changes, this function calls RemoveAllMeshConnections() followed by MakeMeshConnections(channel) — where channel is only the one channel that was just modified. This means all other channels get torn down but never rebuilt. The same issue exists in CheckPowerReturnedRestoreConnections, which loops over all towers calling MakeMeshConnections per tower, meaning channels can be rebuilt multiple redundant times while others are skipped entirely.

Fix:

The solution is a new RebuildAllMeshConnections function that tears everything down once and then rebuilds every distinct active channel in a single pass:

local function RebuildAllMeshConnections()
  RemoveAllMeshConnections()
  local rebuilt = {}
  for _, surface in pairs(game.surfaces) do
    for _, radar in pairs(surface.find_entities_filtered{ name = "wireless-circuit-tower" }) do
      if radar.valid and radar.backer_name ~= default_channel_name then
        if not rebuilt[radar.backer_name] then
          MakeMeshConnections(radar.backer_name)
          rebuilt[radar.backer_name] = true
        end
      end
    end
  end
end

Then replace the body of ProcessFullLinkMesh and CheckPowerReturnedRestoreConnections to call RebuildAllMeshConnections(), and do the same for the MakeMeshConnections call in the power-restore branch of UpdateTowerPowerStates.

Happy to share a fully patched control.lua if that would be helpful.

a day ago

Hey, I would absolutely love to get my hands on your control.lua. <3 I am not a modder and I'm scared of trying to implement the code myself for fear of making everything FUBAR.

a day ago
(updated a day ago)

Update: I tried applying your changes anyway. Got this:

The mod Multi Circuit Repeater (1.0.21) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event Multi_Circuit_Repeater::on_gui_confirmed (ID 166)
Multi_Circuit_Repeater/control.lua:209: attempt to call global 'RemoveAllMeshConnections' (a nil value)
stack traceback:
Multi_Circuit_Repeater/control.lua:209: in function 'RebuildAllMeshConnections'
Multi_Circuit_Repeater/control.lua:317: in function 'ProcessFullLinkMesh'
Multi_Circuit_Repeater/control.lua:610: in function 'CommitRename'
Multi_Circuit_Repeater/control.lua:680: in function <Multi_Circuit_Repeater/control.lua:678>

99% certain it's because I did something wrong.

EDIT: Don't mind me, I'm an idiot learning lua scripting for the first time. Had the order of events wrong and tried to call a function I hadn't declared yet. Doy.

New response