Moon Logic deprecated

by mk-fg

Adds Lua-programmable circuit network combinator. Based on Sandboxed LuaCombinator and LuaCombinator2 mods. Probably won't work in multiplayer games.

Content
2 years ago
1.0 - 1.1
4.97K
Circuit network

b [lua-qiz] "A = red['signal-T'] or red['signal-S']" don't work

3 years ago
(updated 3 years ago)

Example 1:

    local T = 1
    if red['signal-T'] then
        T = red['signal-T']
    end
    if red['signal-S'] then
        T = red['signal-S']
    end
    out['signal-T'] = T

This code work fine.

Example 2:

    local T = red['signal-T'] or red['signal-S']
    out['signal-T'] = T

This code should give the same result. But it don't work : out['signal-T'] has no value.

Input values: red['signal-T'] - none, red['signal-S'] - something

3 years ago
(updated 3 years ago)

local T = red['signal-T'] or red['signal-S']

In this example, red['signal-T'] will return 0 (for missing signal, as mentioned in the help window), red['signal-S'] will return let's say 5.
Only logical-false values in Lua language are "nil" and "false", so local T = 0 or 5 will assign 0 to T.
Last part might indeed be a bit surprising if you are used to other programming languages with C lineage, where 0 is equivalent to false.

I'd probably use a kind of ternary operator in this example-case:
local T = red['signal-T'] == 0 and red['signal-T'] or red['signal-S']
Lua doesn't have A ? B : C notation, but due to same rule, you can be sure that B or C will never fallback to C if B is a number.

3 years ago

Example 1:
if red['signal-T'] then
if red['signal-S'] then
This code work fine.

Stuff inside these if's should always be executed due to same thing as above, so it works simply because T gets re-assigned to signal-S value in this case, and it obviously won't work if you swap places of these condition blocks. If it doesn't work like that, should be a bug.

But it don't work : out['signal-T'] has no value.

Technically zero will be assigned, but factorio just hides/ignores these in UI, I think, as all signals read "0" by vanilla combinators by default.
That last bit and to avoid always typing (red.stone or 0) + 30 when using these is the rationale for default-0 operation (nil + number = error!).

3 years ago
(updated 3 years ago)

In this example, red['signal-T'] will return 0

Oh, I thought it would return nil if signal-T not defined.
Now I understand.
Sorry for wrong bugreport.

3 years ago
(updated 3 years ago)

Oh, I thought it would return nil if signal-T not defined.

Have you clicked the "?" button at the top of the combinator window?
It should open an in-game description for how all these things work, which has this for red/green tables:

Might be helpful to read through all of the things there - would know what to expect from them, though of course tinkering is it's own fun too :)

New response