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

g [lua-qiz] Each Anything Everything

2 years ago

Here is some code for checking Each Anything and Everything (similar to circuit logic).
out = {}
-- each
for o,c in pairs(red) do
if c < 0 then
out[o] = c
end
end
-- anything
local anything = false
for o,c in pairs(red) do
if c < 0 then
anything = true
end
end
if anything then out.wood = 5 end
-- everything
local everything = true
for o,c in pairs(red) do
if not (c < 0) then
everything = false
end
end
if everything then out.coal = 5 end

2 years ago

Not sure what the question is, but of course you'd probably want much simplier decider combinator(s) for this simple task.
Also I think with conditional anything/everything loops you can put "break" in there to stop looping after result is already decided.

2 years ago

New to lua, this helped me figure out the correct syntax for the "each" functionality. For some reason I thought I could use next and I am sure there is a way that I am just not getting. Thanks for the example!

2 years ago

If you mean lua's next(), then yeah, apparently not - returns internal '_e' value from raw table.
There doesn't seem to be a way to override its result via metatables in lua 5.2, so guess for "anything", it has to be done via pairs().
Also above examples use specific condition for all operations (signal value < 0), which won't really work with next() anyway, as it only returns first key in a table without checking any of that.

New response