Page 1 of 1

entity.input_signals / entity.output_signals

Posted: Tue Jul 21, 2015 9:08 pm
by ljdp
Interface to get the input and output signals for any entity that uses the logic system.

Code: Select all

-- read / write
entity.input_signals
entity.output_signals

Re: entity.input_signals / entity.output_signals

Posted: Tue Jul 21, 2015 10:05 pm
by ratchetfreak
ljdp wrote:Interface to get the input and output signals for any entity that uses the logic system.

Code: Select all

-- read / write
entity.input_signals
entity.output_signals
is the output read/write? as in can you set the output to whatever you want

Re: entity.input_signals / entity.output_signals

Posted: Thu Jul 23, 2015 11:09 am
by DaveMcW
local condition = game.player.selected.get_circuit_condition(1)
condition.parameters.first_signal.name = "signal-B"
game.player.selected.set_circuit_condition(1, condition)

The 1 can be replaced by any integer, it does not seem to matter. But it wants an integer as the first parameter.

Re: entity.input_signals / entity.output_signals

Posted: Thu Jul 23, 2015 1:32 pm
by ljdp
DaveMcW wrote:local condition = game.player.selected.get_circuit_condition(1)
condition.parameters.first_signal.name = "signal-B"
game.player.selected.set_circuit_condition(1, condition)

The 1 can be replaced by any integer, it does not seem to matter. But it wants an integer as the first parameter.
That doesn't seem to do what I mean. What I mean is getting the real-time signal information (for example when you hover over decider combinator the GUI will show you what the input signals are) whereas get_circuit_condition returns the 'query' inside the logic entity.

For example, in the screenshot:
Image
game.player.selected.input_signals should return:

Code: Select all

{
  { name = "signal-C", count = 10 },
  { name = signal-B", count = 5 },
  { name = "signal-A", count = 1 }
}

Re: entity.input_signals / entity.output_signals

Posted: Thu Jul 23, 2015 11:54 pm
by DaveMcW
Ah.

I handle writing by temporarily reprogramming the combinator for 1 tick. But there does not seem to be a way to read it.

Re: entity.input_signals / entity.output_signals

Posted: Sat Aug 08, 2015 6:30 am
by GopherAtl
DaveMcW wrote:Ah.

I handle writing by temporarily reprogramming the combinator for 1 tick. But there does not seem to be a way to read it.
Oh, *now* I notice this thread and see your comment XD somehow this topic managed to avoid the search terms I tried earlier. Just arrived at the same approach, though it doesn't seem like you have to wait a tick, unless either get_circuit_condition or set_circuit_condition are, internally, waiting a tick without me realising it - but actually, no, can't be because I tested it by writing a function that does a binary search to determine the value of a specific signal by doing 32 tests, and that would take half a second if it were waiting a tick each time. Even though the effects don't spread across circuit networks until the next tick, changing the condition seems to immediately cause a new call to get_circuit_condition to return the updated value for fulfilled.

Re: entity.input_signals / entity.output_signals

Posted: Thu Aug 13, 2015 11:58 pm
by DaveMcW
GopherAtl wrote:I tested it by writing a function that does a binary search to determine the value of a specific signal by doing 32 tests
Very clever! So we have hacks for both reading and writing.

Now we just need a library that wraps them with a simple API.

Re: entity.input_signals / entity.output_signals

Posted: Sun Apr 17, 2016 6:24 pm
by JasonC
DaveMcW wrote:Very clever! So we have hacks for both reading and writing.
What's the hack for reading? I don't see it here.

Re: entity.input_signals / entity.output_signals

Posted: Mon Apr 18, 2016 8:48 am
by ratchetfreak
JasonC wrote:
DaveMcW wrote:Very clever! So we have hacks for both reading and writing.
What's the hack for reading? I don't see it here.
binary search using a less then and testing active

Re: entity.input_signals / entity.output_signals

Posted: Mon Apr 18, 2016 2:35 pm
by JasonC
ratchetfreak wrote:
JasonC wrote:
DaveMcW wrote:Very clever! So we have hacks for both reading and writing.
What's the hack for reading? I don't see it here.
binary search using a less then and testing active
Oh. That wouldn't work, though. It takes multiple ticks. If the signal value changes during the middle of the search the "read" can fail. That'd be very likely to happen for e.g. item counts, tanker levels, etc.

Re: entity.input_signals / entity.output_signals

Posted: Mon Apr 18, 2016 3:06 pm
by ratchetfreak
JasonC wrote:
ratchetfreak wrote:
JasonC wrote:
DaveMcW wrote:Very clever! So we have hacks for both reading and writing.
What's the hack for reading? I don't see it here.
binary search using a less then and testing active
Oh. That wouldn't work, though. It takes multiple ticks. If the signal value changes during the middle of the search the "read" can fail. That'd be very likely to happen for e.g. item counts, tanker levels, etc.
Actually according to tests the active property updates with the condition so a binary search in one tick will converge on the value.

Re: entity.input_signals / entity.output_signals

Posted: Mon Apr 18, 2016 5:21 pm
by JasonC
ratchetfreak wrote:
JasonC wrote:
ratchetfreak wrote:binary search using a less then and testing active
Oh. That wouldn't work, though. It takes multiple ticks. If the signal value changes during the middle of the search the "read" can fail. That'd be very likely to happen for e.g. item counts, tanker levels, etc.
Actually according to tests the active property updates with the condition so a binary search in one tick will converge on the value.
Now that is cool. I will play with it later on my own; but how is performance? Is it pretty forgiving? I can definitely use that active update behavior to simplify this inserter.

BTW are you also ratchetfreak on Stack Exchange? If so, *fist bump*.

Re: entity.input_signals / entity.output_signals

Posted: Mon Apr 18, 2016 5:27 pm
by Choumiko
JasonC wrote:Oh. That wouldn't work, though. It takes multiple ticks. If the signal value changes during the middle of the search the "read" can fail. That'd be very likely to happen for e.g. item counts, tanker levels, etc.
It works https://github.com/Choumiko/SmartTrains ... l.lua#L552 (all credits for this function to GopherAtl), just do it in one tick.
Assuming entity is a lamp with a condition set, call it like: deduceSignalValue(entity,entity.get_circuit_condition(1).condition.first_signal,1) to get the value of the signal that is set in the lamp

Re: entity.input_signals / entity.output_signals

Posted: Mon Apr 18, 2016 6:07 pm
by Rseding91
I'm planning on adding a "LuaCircuitNetwork" object in 0.13 but I've got some internal things to sort out before doing so. It would solve all of the requests here plus some additional ones.

Re: entity.input_signals / entity.output_signals

Posted: Mon Apr 18, 2016 8:03 pm
by JasonC
Rseding91 wrote:I'm planning on adding a "LuaCircuitNetwork" object in 0.13 but I've got some internal things to sort out before doing so. It would solve all of the requests here plus some additional ones.
The new possibilities that will open up for mods will be awesome. Yet another thing on the list of reasons I'm super excited for 0.13!

Re: entity.input_signals / entity.output_signals

Posted: Sat Apr 30, 2016 6:05 am
by binbinhfr
Rseding91 wrote:I'm planning on adding a "LuaCircuitNetwork" object in 0.13 but I've got some internal things to sort out before doing so. It would solve all of the requests here plus some additional ones.
Oh yes, please add this ! :-)