Would this be possible?

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
Optymistyk
Long Handed Inserter
Long Handed Inserter
Posts: 52
Joined: Sun Jun 14, 2020 9:41 pm
Contact:

Would this be possible?

Post 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

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Would this be possible?

Post 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).
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

mrvn
Smart Inserter
Smart Inserter
Posts: 5704
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Would this be possible?

Post 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.

pleegwat
Filter Inserter
Filter Inserter
Posts: 258
Joined: Fri May 19, 2017 7:31 pm
Contact:

Re: Would this be possible?

Post 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.

Post Reply

Return to “Modding discussion”