Page 1 of 1

Custom ArithmeticCombinator

Posted: Wed Sep 22, 2021 12:32 pm
by juggernaut
This is my first mod. I want to create my combinator with new logic, it must have a signal input and an output. I took the arithmetic combinator as a prototype.
I figured out how to read the signal that comes to the combinator, but didn't figure out how to output it.
I call

Code: Select all

entity.get_or_create_control_behavior ()
and I get the LuaArithmeticCombinatorControlBehavior object. He has a field parameters, but how does it work? How can I tell the combinator to output a certain signal to its outputs? I also did not understand with ArithmeticCombinatorParameters, since the amount of signal cannot be specified there.
Sorry for my googletranslate :D

Re: Custom ArithmeticCombinator

Posted: Wed Sep 22, 2021 12:46 pm
by Stringweasel
Best would be to download a mod that does something similar to what you want to do, and then see what they did. Maybe something like this? https://mods.factorio.com/mod/UsefulCombinators

And for reference, this is how I've managed to change the output of a constant combinator in one of my mods. Should be very similar for other combinators.

Code: Select all

local entity = game.surfaces.nauvis.find_entity("constant-combinator", {85.5, -72.5}) 
local control = entity.get_or_create_control_behavior() 
control.enabled = true -- This turned on the constant combinator (was previously off)
Good luck! :)

Re: Custom ArithmeticCombinator

Posted: Wed Sep 22, 2021 1:04 pm
by Stringweasel
Realized my previous post wasn't very helpful. Looking at other mods like this one it seems like it's not easy modifying other combinators to output what you want it to output. It looks like you would need to put your output on a invisible constant combinator.
https://mods.factorio.com/mod/stack-combinator

Re: Custom ArithmeticCombinator

Posted: Wed Sep 22, 2021 1:24 pm
by torne
I don't think you can set the output if you're using the arithmetic combinator as the prototype. That already has a behaviour associated with it: it does arithmetic, according to the settings in its control behaviour.

If you want to output signals of your choice you would need to use a constant combinator prototype. Depending what you're trying to do you might need to make a composite entity, with more than one actual game object with different prototypes; e.g. if you need to read input signals.

Re: Custom ArithmeticCombinator

Posted: Wed Sep 29, 2021 11:19 am
by juggernaut
Thanks for the tip. I seem to have figured it out with this, but 1 more question has appeared.
I copied the prototype from ArithmeticCombinator and changed its name. But when you click on the object, the ArithmeticCombinator menu opens anyway. How can we get out of this?
1) I know that it is possible in principle to indicate that the menu of the object does not open (but I do not need this).
2) If I need to open my custom menu, then I must specify player.opened = my_window, otherwise the ArithmeticCombinator menu will open.
Am I doing it right or how should it be right?