wiremod/wire

Weird behaviour with triggers

Closed this issue · 7 comments

Describe the bug
I have a project that uses fairly comlex control system so I divided E2 chips by functions. I have a chip that calculates control forces and another that will apply those forces. To make sure that one chip trigger execution of another I make sure that control chip is executed first and then it flips output variable so that it should trigger force processing chip. Otherwise it seems that force processing chip will work with older outputs of control chip(older by one frame)

To Reproduce
Create a chip that calculates control signal using PID regulator. At the end of code type SyncOut = !SyncOut(which is in @outputs part) so it would trigger execution of another chip that process forces. Also have in @output force vector itself.
Even though force processing chip has trigger only by SyncOut input it appears as if the chip gets triggered twice. As the stable control system becomes unstable
I am assuming that is just basic issue with trigger system but is there any way to make control system such that chip would use newest parameters for control without triggers?

Expected behavior
Expected behaviour is that it would work in a usual way. Maybe that is happening because my request is kinda impossible and you cant synchronise chips?

Screenshots
If applicable, add screenshots to help explain your problem.

Don't know what you mean it triggers twice. I guess you are expecting it to only trigger if the input is 1? Input triggers will trigger on any change of the input, so 1 or 0 will trigger it.

You could disable triggers (@trigger none) and use a timer to regularly poll the inputs instead. Otherwise I think what you're looking for is just to check that Input != 0 as thegrb93 suggested.

Don't know what you mean it triggers twice. I guess you are expecting it to only trigger if the input is 1? Input triggers will trigger on any change of the input, so 1 or 0 will trigger it.

No it isn't what I meant. I made it trigger by sinlge variable sync. Sync flickers between 1 and 0 every game tick. So having a chip with input that contstably flickers between 1 and 0 every tick should be same as usung runOnTick or event tick() but it doesnt behave same way. Maybe I should write in discord server and show what I mean. I use trigger because different chips have to be executed at different moments and with event tick I have no idea in what order chip are working. It is probably not super important for some chips to be delayed by single frame but it's annoying and makes the system inconsistent. So if I a clock chip that outputs variable sync that constanly flickers(the code looks like runOnTick(1)
Sync=!Sync) and another chip that inputs that variable and I have it work as trigger for the second chip. Shouldn't the second chip also work every tick but after clock chip has executed its code? Or is it something I am not getting?

E2 chips can trigger multiple times per tick, so Sync = !Sync can be ran multiple times in one tick. Maybe that's what you're missing?

use if (~InputName) { to check if the current execution was caused by that input. this will filter out the "multiple executions in a single tick" thing

and by now there's probably an event for input triggers which could be used for that, which is probably better

use if (~InputName) { to check if the current execution was caused by that input. this will filter out the "multiple executions in a single tick" thing

and by now there's probably an event for input triggers which could be used for that, which is probably better

Thank you guys