Circuit Radio


Adds a simple 1x1 radio node that joins a virtual red/green circuit network selected by one signal/value channel.

Content
a month ago
2.0
129
Circuit network

i New ideas

a month ago
(updated a month ago)

Hey, this is a cool mod. I've been looking for something with channel isolation for a while and thought about writing one myself, but I don't have much experience with it.
It's very convenient for modularly separating logic blocks.
I decided to expand on it by adding a switch for global and local.

Author: IGRIKRUS <*****>
Date:   Sun May 31 00:32:09 2026 +0200

    add switch channel global and local

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0dc7b4b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/.vscode
\ No newline at end of file
diff --git a/control.lua b/control.lua
index 8768438..41965d6 100644
--- a/control.lua
+++ b/control.lua
@@ -19,6 +19,7 @@ local OPEN_INPUT = "circuit-radio-open"
 local GUI_NAME = "circuit_radio_gui"
 local GUI_SIGNAL = "circuit_radio_signal"
 local GUI_VALUE = "circuit_radio_value"
+local GUI_IS_GLOBAL = 'circuit_radio_is_global'
 local GUI_SAVE = "circuit_radio_save"
 local GUI_CANCEL = "circuit_radio_cancel"

@@ -143,13 +144,19 @@ local function normalize_channel_value(value)
   return math.floor(number)
 end

-local function make_channel_key(entity, channel_signal, channel_value)
+local function make_channel_key(entity, channel_signal, channel_value, channel_is_global)
   local signal = normalize_signal_id(channel_signal)
   if not (entity and entity.valid and signal) then
     return nil
   end

-  return "surface:" .. entity.surface.index
+  local surface = "surface_local:" .. entity.surface.index
+
+  if channel_is_global then
+    surface = 'surface_global:'
+  end
+
+  return surface
       .. "|force:" .. entity.force.index
       .. "|" .. signal_to_text(signal)
       .. ":" .. normalize_channel_value(channel_value)
@@ -525,7 +532,7 @@ local function update_channel_render(radio)
     return
   end

-  local channel_key = make_channel_key(radio.entity, radio.channel_signal, radio.channel_value)
+  local channel_key = make_channel_key(radio.entity, radio.channel_signal, radio.channel_value, radio.channel_is_global)
   if not channel_key then
     radio.entity.custom_status = nil
     destroy_channel_render(radio)
@@ -598,7 +605,7 @@ local function refresh_radio_connections(radio)
   connect_radio_to_bridge(radio)
   update_channel_render(radio)

-  local new_key = make_channel_key(radio.entity, radio.channel_signal, radio.channel_value)
+  local new_key = make_channel_key(radio.entity, radio.channel_signal, radio.channel_value, radio.channel_is_global)
   if radio.channel_key == new_key then
     return
   end
@@ -817,6 +824,37 @@ local function open_radio_gui(player, entity)
     allow_negative = false
   }

+  local mode_flow = frame.add{
+    type = "flow",
+    direction = "horizontal",
+    style = "player_input_horizontal_flow"
+  }
+
+  mode_flow.style.vertical_align = "center"
+
+  mode_flow.add{
+    type = "label",
+    caption = "Local channel"
+  }
+
+  local switch_state = "left"
+  if radio.channel_is_global == true then
+    switch_state = "right"
+  end
+
+  mode_flow.add{
+    type = "switch",
+    name = GUI_IS_GLOBAL,
+    switch_state = switch_state,
+    allow_none_state = false,
+    tooltip = "Choose between Global network (all surfaces) and Local network (this planet only)."
+  }
+
+   mode_flow.add{
+    type = "label",
+    caption = "Global channel"
+  }
+
   local button_flow = frame.add{
     type = "flow",
     name = "circuit_radio_button_flow",
@@ -859,14 +897,22 @@ local function save_radio_gui(player, frame)

   local signal_button = find_child_by_name(frame, GUI_SIGNAL)
   local value_field = find_child_by_name(frame, GUI_VALUE)
+  local is_global_switch = find_child_by_name(frame, GUI_IS_GLOBAL)

-  if not (signal_button and signal_button.valid and value_field and value_field.valid) then
+  if not (signal_button and signal_button.valid and value_field and value_field.valid and is_global_switch and is_global_switch.valid) then
     destroy_radio_gui(player)
     return
   end

   radio.channel_signal = normalize_signal_id(signal_button.elem_value)
   radio.channel_value = normalize_channel_value(value_field.text)
+
+  if is_global_switch.switch_state == "right" then
+    radio.channel_is_global = true;
+  else
+    radio.channel_is_global = false
+  end
+
   refresh_radio_connections(radio)

   destroy_radio_gui(player)

I'm also thinking of adding a channel browsing interface to make searching easier, but I have no idea how to do it without on_tick yet. There's a mod similar to what I need called CircuitHUD-V2. It would be nice to add something like that to this mod.

There's also a minor issue. When selecting a copy or delete area, if the cursor is on the combinator, it opens the interface. It would be nice to fix this somehow.

google translate.

a month ago
(updated a month ago)

If you're interested, I've added this interface.

I can send you the code if needed.

a month ago

I re-created the interface for searching for station locations.

added the flib dependency and made minimal changes to the main code.
I've tested the interface online, and the load is minimal. I wouldn't mind sharing the code so you could review it and maybe even include it in the main build.

a month ago

There's also a minor issue. When selecting a copy or delete area, if the cursor is on the combinator, it opens the interface. It would be nice to fix this somehow.

Thank you for letting me know. Uploaded 0.1.3, this problem should be gone now

a month ago

If you're interested, I've added this interface.

I can send you the code if needed.

Hi igrik. Could you please publish your changes on GitHub or somewhere similar? I'm very interested in your fixes.

a month ago

andriyg81, it would be nice if you add a changelog

a month ago

andriyg81, it would be nice if you add a changelog

added

a month ago
(updated a month ago)

There's also a minor issue. When selecting a copy or delete area, if the cursor is on the combinator, it opens the interface. It would be nice to fix this somehow.

Thank you for letting me know. Uploaded 0.1.3, this problem should be gone now

Hi, thanks for the fix, but I'd also like to fix the number input.

if number > 2147483647 then
number = 2147483647
end

Otherwise, it would be 1.2312123123123e+19

Wouldn't you want to add code to switch from local to global scope? Even in the latest FFF 441 news, the developers added such a switch to the radar.
I wrote an example of code above that works without problems.

Hi igrik. Could you please publish your changes on GitHub or somewhere similar? I'm very interested in your fixes.

I'm still getting used to working with Lua and would like to finish it and redo some of it. Once I'm happy with what I've done, I'll probably upload it to GitLab and post it here.

a month ago

Hi, thanks for the fix, but I'd also like to fix the number input.

if number > 2147483647 then
number = 2147483647
end

Otherwise, it would be 1.2312123123123e+19

Thank you for the number input fix. I incorporated it into the mod. (0.1.5)
Your ideas are excellent, and I do like the local/global scope switch idea. For now, though, I’m trying to avoid adding new features until I iron out the remaining errors and make the current version more stable.
Once the mod is in a cleaner state, I’ll be more comfortable adding features like that. I appreciate the suggestions and the example code.

a month ago

If you're interested, I've added this interface.

I can send you the code if needed.

Hi igrik. Could you please publish your changes on GitHub or somewhere similar? I'm very interested in your fixes.

I have posted my work.

https://github.com/IGRIKRUS/Circuit-Radio-Fork.git

New response