Page 1 of 1

How i can read state of circuit network

Posted: Sat Aug 01, 2015 7:45 pm
by craftoBot
Working on my new mod i found problem, i can't read state of circuit input connected to entity.
May be someone can help me?

Re: How i can read state of circuit network

Posted: Sat Aug 01, 2015 10:08 pm
by ratchetfreak
craftoBot wrote:Working on my new mod i found problem, i can't read state of circuit input connected to entity.
May be someone can help me?
mouse over it and it'll appear on the right

otherwise connect that input network to a power pole and mouse over the pole

Re: How i can read state of circuit network

Posted: Sun Aug 02, 2015 12:15 am
by Xyfi
ratchetfreak wrote:
craftoBot wrote:Working on my new mod i found problem, i can't read state of circuit input connected to entity.
May be someone can help me?
mouse over it and it'll appear on the right

otherwise connect that input network to a power pole and mouse over the pole
I don't think that's what he meant. Since this is the "Modding help"-section.

Re: How i can read state of circuit network

Posted: Sun Aug 02, 2015 2:49 pm
by craftoBot
I mean read state to lua script.

Re: How i can read state of circuit network

Posted: Sat Aug 08, 2015 5:09 am
by GopherAtl
Watching this thread in case anyone knows more, but after poking about a bit I'm inclined to think there is no way, seems the only access available currently is through get_circuit_condition on entities that support connections, which lets us inspect [s](but not modify)[/s] the conditions and, in only some cases, find out if the condition is true via a "fulfilled" field. The fulfilled field seems to be present on lamps and smart inserters. It doesn't seem to be present on decider combinators, despite them having equivalent conditions that are true or false, and no equivalent "result" is accessible on arithmetic accumulators, either. Basically we can just access what's set in the gui, in a read-only way (not tried exhaustively but tried writing a few, it did not change the settings on the devices)

:Edit: just noticed set_circuit_condition, which I'd somehow not noticed previously. Experimenting with it now...

:edit2: ok, tests confirmed, calling set_circuit_condition then immediately calling get_circuit_condition for lamps and smart inserters gives you the fulfilled value for the new condition, no waiting a tick required (unless one of these functions is implicitly waiting a tick and I just don't realise it?)

This means you actually can determine the value of any signal coming in to one of those two devices by doing a binary search, 32 tests of 32 conditions to identify a 32-bit integer value. Not the kind of thing I'd be comfortable doing extensively, but it is technically an option if you don't mind the possible performance hit, or aren't doing the test too frequently.

This function does such a test, if you pass in a valid entity (must be a lamp or smart inserter, or something derived from those), the type of signal (usually "item", or "abstract" for the abstract signals) and name (the item name for items, the abstracts seem to follow the pattern "signal-<X>" where <X> is the signal's identifier - ex, "signal-0" or "signal-A")
the slightly evil function

Re: How i can read state of circuit network

Posted: Sun Aug 09, 2015 12:32 pm
by craftoBot
Thank you! I will try to implement this in my new mod Programmable Controllers for multiple circuit input
https://forums.factorio.com/forum/vie ... 93&t=14649

Re: How i can read state of circuit network

Posted: Sun Aug 09, 2015 2:13 pm
by GopherAtl
@craftobot, cool, just... try not to overuse it too much? It's not a particularly expensive hack or anything, but I'm not sure it's so trivial that, if you were to use it to monitor dozens of signals at a time for each entity, and had a lot of those entities, and were checking it in on_tick, it wouldn't cause performance issues... I'm using it in a mod of my own at the moment, each entity instance only checking 1 signal (and most of them not doing a check at all, actually), and I've throttled it down to checking only on certain ticks. I'm also leaving the condition configured to "= <count>" after each run, so if the value is unchanged, I can just know that from a quick test of "fulfilled" rather than re-perform the check unnecessarily. Thinking I will set it up as a config setting, refresh speed, so players can adjust it as needed, but depending on what you're using the signal values for, polling less than every tick may not be an option...

tl;dr: dirty, dirty hack, use with care

Re: How i can read state of circuit network

Posted: Sun Aug 09, 2015 2:50 pm
by craftoBot
@GopherAtl
I had one nice idea, just let controller to change trigger amount, so player programs will be able to read input count
Also i think, i will add gui with slots for multiple input....
But i will do it later, may be factorio authors add this feature? :D
Thank you for replay)