Page 1 of 1

Would this be possible?

Posted: Wed Aug 05, 2020 4:09 pm
by Optymistyk
I wanted to write a mod that would allow red and green wire channels to be treated separately. Basically it would allow you to do things such as pairwise operations on red/green wires. For example an arithmetic combinator could do [Each(red wire) / Each(green wire)] (pairwise division). I wanted to know if it's even possible before I dive into it

Re: Would this be possible?

Posted: Tue Aug 25, 2020 2:49 pm
by eradicator
Combinator behavior is hardcoded. You'd have to write everything from scratch or do some black magic with invisible combinators to "fake" the behavior you want (similar to how https://mods.factorio.com/mod/circuitissimo does it).

Re: Would this be possible?

Posted: Tue Aug 25, 2020 2:52 pm
by mrvn
And no, you can't even fake it. There is no way to build a circuit for red / green that isn't iterative (and that then takes many ticks). And reading the signals in LUA and performing the math there simply doesn't scale.

Re: Would this be possible?

Posted: Tue Aug 25, 2020 4:42 pm
by pleegwat
Note there are tricks you can do to perform some of these:

Addition is done by connecting multiple wires (possibly isolating signals via +0 or *1)
Subtraction via multiply by -1 and addition.
Squaring is straightforward via (each * each).
Multiplication can be done as ((A + B)² - A² - B²) / 2; make sure to insert appropriate delay combinators to keep signals in sync.

I'm don't know a good one for division. Since you can't have fractional signals, (A * 1/B) won't work. Something like (A * 65536 / B) / 65536 should work, but cuts into your range. If you know the maximum value you expect for B, you could tune the constant to that.