Circuit Wire Poles


Adds small poles for circuit wire connections.

Content
9 days ago
1.1 - 2.1
594
Circuit network

g Wire connection failure after cursor change

1 year, 6 months ago
(updated 1 year, 6 months ago)

Hello,

Thanks for making this mod! I've been tinkering with it a bit for my personal use and I found a bug where a new circuit connection will fail to attach if the wire is grabbed via hotkey while hovering over the pole. The underlying cause is that the cursor-wire check only happens after the selection change event, but not after a cursor change. I fixed this locally by adding a new function which handles the event on_player_cursor_stack_changed. Note that the function is_player_holding_wire just wraps around the conditional you have in the create_viewer_entity function.

function viewer.on_player_cursor_stack_changed(event)
  local player = game.get_player(event.player_index)
  local selected = player.selected
  if selected == nil then
    return
  end
  local holding_wire = viewer.is_player_holding_wire(player)
  if holding_wire and selected.name == "circuit-wire-pole-viewer" then
    viewer.clear_viewer_entity(player)
  elseif not holding_wire and selected.name == "circuit-wire-pole" then
    viewer.create_viewer_entity(player)
  end
end

Hopefully this is of some use to you :)

1 year, 6 months ago

Also, I just realized, you could probably avoid adding a new function and just add another handler to control.lua:

script.on_event(defines.events.on_player_cursor_stack_changed, viewer.on_selected_entity_changed)
9 days ago

Good news! After a long hiatus of being unable to even play Factorio due to life(tm) I finally found some time to get back to touch this mod.
Thanks for this detailled assessment. It was in fact not just adding the event handler but also another if statement, but then it worked just fine. Fixed now :)

New response