Page 1 of 1
LuaCircuitNetwork.signals_changed
Posted: Tue May 25, 2021 10:55 am
by DaveMcW
I would like a read-only boolean property on LuaCircuitNetwork to tell when the contents of a circuit network have changed. I believe this already exists internally, it just needs to be exposed to Lua.
The use case is controlling modded buildings through the circuit network. With a fast way to see if a circuit network has changed, a mod can skip the time-consuming comparison of individual signals on ticks where nothing happened.
Re: LuaCircuitNetwork.signals_changed
Posted: Sat Apr 15, 2023 10:10 am
by Hares
Great suggestion.
+1 on that
Re: LuaCircuitNetwork.signals_changed
Posted: Sat Apr 15, 2023 2:42 pm
by Rseding91
Changed compared to what?
Re: LuaCircuitNetwork.signals_changed
Posted: Sat Apr 15, 2023 3:17 pm
by Nidan
Judging from the final sentence, compared to the previous tick.
Re: LuaCircuitNetwork.signals_changed
Posted: Sun Apr 16, 2023 9:18 am
by boskid
Such value is indeed available but it is not save-load stable and as such i am not allowed to expose that without risks of desyncs. Due to way circuit network is implemented in 1.1, it is recomputing some values during first update after save was loaded (by client) even when those computations are not required on server. There are also some annoying behaviors related to this value as it may be spuriously set by some entities (i think roboport may be one of them) every tick even if the signals are not changing so it may not be useful in some cases. I may reconsider this once 1.2 would be released since the circuit network in 1.2 is implemented slightly differently causing less spurious notifications about changed signals and the value in 1.2 is save-load stable making it possible to be exposed here.
Re: LuaCircuitNetwork.signals_changed
Posted: Sun Apr 16, 2023 10:15 pm
by braxbro
DaveMcW wrote: ↑Tue May 25, 2021 10:55 am
I would like a read-only boolean property on LuaCircuitNetwork to tell when the contents of a circuit network have changed. I believe this already exists internally, it just needs to be exposed to Lua.
Why not make an event out of it?
Re: LuaCircuitNetwork.signals_changed
Posted: Sun Apr 16, 2023 11:19 pm
by mrvn
braxbro wrote: ↑Sun Apr 16, 2023 10:15 pm
DaveMcW wrote: ↑Tue May 25, 2021 10:55 am
I would like a read-only boolean property on LuaCircuitNetwork to tell when the contents of a circuit network have changed. I believe this already exists internally, it just needs to be exposed to Lua.
Why not make an event out of it?
That would generate an event for every single circuit network that has a change. You can't just listen to events on a specific circuit network (which would be really great).
Maybe there could be a new CircuitNetworkListener prototype, a new entity, that generates events. That way you would only get events where that entity is placed and connected.
Re: LuaCircuitNetwork.signals_changed
Posted: Mon Oct 09, 2023 9:49 am
by Hares
mrvn wrote: ↑Sun Apr 16, 2023 11:19 pm
That would generate an event for every single circuit network that has a change. You can't just listen to events on a specific circuit network (which would be really great).
Maybe there could be a new CircuitNetworkListener prototype, a new entity, that generates events. That way you would only get events where that entity is placed and connected.
I suppose an per-entity or per-entity-prototype event could also be a soultion, since it is the most-used case.
Plus, unlike per-network event, this will allow not worrying about player rewiring their stuff or scripts performing multiple (un)wire actions on the same tick.
Re: LuaCircuitNetwork.signals_changed
Posted: Sun Jul 07, 2024 3:43 am
by scruffyvoltherder
+1
This would be very useful