Circuit network change detection questions.

Place to post guides, observations, things related to modding that are not mods themselves.
scruffyvoltherder
Inserter
Inserter
Posts: 21
Joined: Fri Jun 14, 2024 12:33 am
Contact:

Circuit network change detection questions.

Post by scruffyvoltherder »

I'm working on a PLC mod where I need to be able to tell when the signals change on an input point. I need to be able to detect the changes and read what the signal is even when the signal changes every tick.

03-25-2025, 14-47-32.png
03-25-2025, 14-47-32.png (1.57 MiB) Viewed 127 times
The combinator labeled IO represents anything external connected to my PLC entity. Out is where the output is set. It is ignored by the change detection because of the multiply combinator hooked up with green wire. If the signal from IO changes, the circuit network connected to chg will have a signal for one tick.

The options I'm looking at are:
1. Check if LuaCircuitNetwork.signals on the circuit network connected to chg is not null. This is the version I'm currently testing. The polling doesn't cause too much impact to update time, but i'd still like to reduce it as much as possible.
2. Check if LuaLampControlBehavior.disabled on the lamp is false
3. Place an item for the inserter to pick up, register it with register_on_object_destroyed() and wait for on_object_destroyed() event to fire

Is there any performance difference between doing a nil check on a LuaCircuitNetwork.signals, vs a true/false check on LuaLampControlBehaviour.disabled?
I'm thinking I can call get_circuit_network() or get_control_behaviour() once, and keep the result in storage.

If i use a condition on an inserter, then I don't have to do polling.
The documentation for on_object_destroyed states
Depending on when a given object is destroyed, this event will be fired at the end of the current tick or at the end of the next tick. The event's timing is independent of the in-world object being destroyed.
If an entity on the ground is picked up by an inserter, is there any consistency as to when the on_onject_destroyed() will be called?
Post Reply

Return to “Modding discussion”