Page 1 of 1

Request for a small guide how to read / send signals

Posted: Thu Mar 01, 2018 7:01 am
by GalactusX31
Hi, I have tried to gather information about it, but the information I have found is confusing, or very little clarifying, so, I come here to ask if someone can do some small guide on how to make an entity, interact with the virtual signs

1. How to detect if an entity receives a signal, by the green or red wire.
2. How to send signals through the red and green wires or both.
3. How to know what signals are circulating on those wires.
4. How to save those signals between saved games.

Since the wiki and the API page contain rather few "practical" examples I would appreciate small examples of "how to do for", thank you very much.
Any link with more information, is welcome

Re: Request for a small guide how to read / send signals

Posted: Sat Mar 03, 2018 8:48 am
by darkfrei
You can read or send to connected wires.
See also code of https://mods.factorio.com/mod/UniqueSignal

Re: Request for a small guide how to read / send signals

Posted: Sun Mar 04, 2018 11:47 pm
by GalactusX31
thanks for the answer and the reference, but I still need something simpler ... something like:

this function is to know if an entity receives a virtual signal.
this other function is to send a virtual signal.

I know it's easy to say, look at this mod, or look at this other mod ... the hard part is that everyone has their own style when it comes to structuring their code, and that only makes it confusing.

Re: Request for a small guide how to read / send signals

Posted: Mon Mar 05, 2018 12:43 am
by eradicator
I'm really not into that part of the api, only having used it once..., but as nobody else seems to answer, i'll try from (faded) memory:

First you read an entities control behavior via:
LuaEntity.get_or_create_control_behavior() or LuaEntity.get_control_behavior()
http://lua-api.factorio.com/latest/LuaC ... olBehavior

then you extract the circuit network channels:
LuaControlBehavior.get_circuit_network(defines.wire_type.red)
LuaControlBehavior.get_circuit_network(defines.wire_type.green)
http://lua-api.factorio.com/latest/LuaC ... uitNetwork

then you can read signals with:
LuaCircuitNetwork.get_signal()

And i haven't done writing signals so i don't know how that part works. You probably have to write a table of signals somewhere... digging through mods that already do it seems to be your only option :P.

Re: Request for a small guide how to read / send signals

Posted: Mon Mar 05, 2018 2:07 am
by GalactusX31
thanks for the information, I hope that someone who has worked with signals, be kind enough to write a little "how to use" code

Re: Request for a small guide how to read / send signals

Posted: Mon Mar 05, 2018 8:23 am
by GalactusX31
I think that due to the lack of information and guides on the matter, I will leave aside the topic of making mods

Re: Request for a small guide how to read / send signals

Posted: Mon Mar 05, 2018 9:43 am
by eradicator
GalactusX31 wrote:I think that due to the lack of information and guides on the matter, I will leave aside the topic of making mods
Well. Modding is hard if you lack the patience to dig through other peoples shit code like everyone else... :mrgreen:

Re: Request for a small guide how to read / send signals

Posted: Mon Mar 05, 2018 10:52 am
by GalactusX31
it's not about patience, it's about asking for help one day, another day, another day ... and the only answer I receive is, learn lua.

Currently, modding factorio grows every day, many functions are added, updating, and I would like to have a place to go, and learn how things should be done, not only see the functions, but see the necessary code to make them work properly.

I have many saved references of pages oriented to LUA programming, handling of tables, functions, events ... but it is "orphan" information, because without a context they have no meaning or application.

Do not misinterpret my words, I am very grateful for the help I have been given.

Re: Request for a small guide how to read / send signals

Posted: Mon Mar 05, 2018 1:16 pm
by mrvn
As a side node: There is no way to detect the entity getting a signal. The signal wire has signals on it every tick and every tick you have to check the signals to see if something changed that the entity is interested in.

For anything with more than 10 entities that quickly becomes an UPS killer. And then you have to throttle back and maybe only check signals once a second and react slower to changed signals. Or only read signals when some other event occurs, like a train arriving, that signals you might have to react to signals.

Re: Request for a small guide how to read / send signals

Posted: Mon Mar 05, 2018 3:45 pm
by GalactusX31
mrvn wrote:As a side node: There is no way to detect the entity getting a signal. The signal wire has signals on it every tick and every tick you have to check the signals to see if something changed that the entity is interested in.

For anything with more than 10 entities that quickly becomes an UPS killer. And then you have to throttle back and maybe only check signals once a second and react slower to changed signals. Or only read signals when some other event occurs, like a train arriving, that signals you might have to react to signals.
Thanks for the note, could you give an example of what it would be like to "check the signs to see if anything changes that the entity is interested in", I mean, some simple code, not a reference to a mod or reference to a page of the factorio API or the wiki (they only have the references to the functions, without any practical example), thanks in advance

Re: Request for a small guide how to read / send signals

Posted: Tue Mar 06, 2018 12:55 am
by eradicator
mrvn wrote:As a side node: There is no way to detect the entity getting a signal. The signal wire has signals on it every tick and every tick you have to check the signals to see if something changed that the entity is interested in.
If you're looking for only one signal you can use the .fullfilled condition on a cached control_behavior. Which is...moderately fast. 20ish entities per tick cost about 0.08 as far as i remember.
http://lua-api.factorio.com/latest/Conc ... cification
GalactusX31 wrote:it's not about patience, it's about asking for help one day, another day, another day ... and the only answer I receive is, learn lua.
I think you have a fundamental misconception of how programming works. And i'm not sure anything i can say here can change that. Every programmer on earth deals with the fundamental issue of trying to figure out how the fuck something works. Mostly all on their own, by trial an error, reading tons of unhelpful pages, sifting through other peoples code, trying to find that one needle in the haystack, while fighting the inner agony of "how the fuck do i do this". And not all of them are lucky enough to have a good documentation like the factorio api pages. The ones that you see as "orphan information" becaues you as of yet lack the knowledge to make use of them. Everyone would like a generic place that magically offers the exact solution to the problem they're trying to solve at the time, but who should ever write that? And if my answers so far (i remember another thread) are the same "learn lua" category for you then...i don't really want to help you anymore, because my time is limited too.