Zomis / FactorioMods

Various mods for the game Factorio
https://mods.factorio.com/mods/zomis
MIT License
15 stars 7 forks source link

Odd behavior on Advanced Combinator #42

Closed adalast closed 4 years ago

adalast commented 4 years ago

So I'm trying to use the Advanced Combinator to automate sat production in conjunction with the Crafting Combinator, but it is giving me some issues. Specifically, I am currently trying to get the an automation for Solar Panels 3s. I have the reads coming in from my storage to determine the cases on what is present, but after that is where it falls apart. I have tried a bitwise-and and an addition to see if I can get the triggers to fire right, but I cannot. I have tracked it down to not understanding what the const field is for at the end of the value_of_signal function. I am assuming that is to read the value on the combinator rather than the incoming line. Maybe that is my issue. I want to do my comparisons and get my boolean values, then use those to determine what to craft. What am I not getting?

if(compare(green(this,item/solar-panel),>,const(0)),set_signal(const(7),signal(signal_type(virtual/signal-0),const(1)))); if(compare(green(this,item/solar-panel-2),>,const(0)),set_signal(const(8),signal(signal_type(virtual/signal-1),const(1)))); if(compare(green(this,item/solar-panel-3),<,const(300)),set_signal(const(9),signal(signal_type(virtual/signal-2),const(1)))); if(compare(add(value_of_signal(signal(signal_type(virtual/signal-0),const(1))),value_of_signal(signal(signal_type(virtual/signal-0),const(1)))),=,const(2)),set_signal(const(1),signal(signal_type(virtual/signal-A),const(1))));

Zomis commented 4 years ago

What is the problem you are experiencing in the game?

Do you have a savegame that I could check?

adalast commented 4 years ago

I could submit my savegame, yeah. Honestly, I am getting incorrect outputs from the function. When I do the bitwise-and with constants, it processes correctly, the instant I switch to value_of_signal() it starts messing up and giving me incorrect results.

adalast commented 4 years ago

The savegame is 140 hours of spaghetti though.

Zomis commented 4 years ago

Ok, so if you do this part: value_of_signal(signal(signal_type(virtual/signal-0),const(1)) You will create a signal of type virtual/signal-0 with the constant value 1. Then you will take the value of that signal, which will be 1. So that part can essentially be replaced with const(1).

Does this make it clearer what's going on?

adalast commented 4 years ago

Not exactly, how do I get the value of a signal that is being generated by the combinator?

Zomis commented 4 years ago

If you are looking for a signal that will be output in the current tick, use current If you are looking for a signal that was output in the last tick, use previous The logic for this can be found in https://github.com/Zomis/FactorioMods/blob/master/advanced-combinator_0.17.0/logic/processing.lua

Does that help?

Zomis commented 4 years ago

Due to lack of response, I assume that all questions were clarified and the problem solved. Get back to me if that's not the case.