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 [fixed] Iterating through inputs

4 years ago
(updated 4 years ago)

Okay so I am trying to write a program that gets the contents of a chest, which can be anything, and do stuff with the item type and the item amount. So I am trying to iterator through the inputs and just print out the signal name and value for right now. However I am getting an error.

-- My Code
debug = true
delay = 1000000000

for i, v in pairs(red) do
game.print(i, v)
end

error message:

env-before :: {a = {}, delay = 1, var = {}}
out-before :: {}
used-inputs :: {["red[coal]"] = 104783}
env-after :: {a = {}, debug = true, delay = 1000000000, var = {}}
out-after :: {}
out-sync=true out-diff :: {}
error :: RuntimeError: 'color': table expected, got number
stack traceback:
[string "debug = true..."]:5: in main chunk
[C]: in function 'pcall'
Moon_Logic/control.lua:443: in function 'run_moon_logic_tick'
Moon_Logic/control.lua:416: in function <Moon_Logic/control.lua:397>
Script @Moon_Logic/control.lua:215: -- moon-logic [1084042]: --- debug-run end [tick=8854738] ---

This code runs correctly outside of moon logic/factorio:

red = {}
red.coal = 104783
for i, v in pairs(red) do
print(i, v)
end

which correctly prints

coal 104783

What going wrong?

4 years ago
(updated 4 years ago)

Unrelatedly, I would like it if there was a print out of current environment variables (besides the debug output). And/or a button to delete current environment variables.

4 years ago

game.print(i, v)
...
error :: RuntimeError: 'color': table expected, got number

Issue is that game.print is not a print(), it's a function for printing to console log for all players with a given color:
https://lua-api.factorio.com/latest/LuaGameScript.html#LuaGameScript.print
Signature is game.print(message, color), and you passed it a number as a "color" argument, which should be either {r,g,b} or {r=n, g=n, b=n} table.

print(i, v) - that's lua's print() function, which converts all its arguments to strings and prints them with some tab offsets to game's stdout iirc.
I think it's problem, and why it's not advertised in help window (it's base lua, doesn't really need to be), is that such output shouldn't end up in factorio log, only its stdout, which can be hard to get on some platforms or unless you start game in a terminal or something.

Guess there should probably be a wrapper for game.print to avoid confusion, as I think it's nature is not well-explained in help window either atm...

Unrelatedly, I would like it if there was a print out of current environment variables (besides the debug output).
And/or a button to delete current environment variables.

Oh, that's a good idea, probably should be printed in a separate window though, as unlike signals they might have complex free-form values, and there can be a lot of them.
Thanks for suggestion!

4 years ago

print(i, v) - that's lua's print() function

That one doesn't seem to be even set in the combinator environment, which I guess is fine too, as it avoids confusion wrt "where the hell it prints to".
Also, forgot to mention, for printing to factorio log, you want the game.log() one, which should at least be mentioned in the reference window:

4 years ago

Ah so I just have to do game.print(i .." ".. v) instead
Thanks

4 years ago

Yeah, though I'll probably add a wrapper to make it more intuitive anyway, and maybe add direct print as "game.print_color" or something.

4 years ago

game.print(i .." ".. v)

Another way to format this in lua would be e.g. game.print(('wire-signal[%s] = %s (%s)'):format(key, value, color)), which can be handy with more values, to have template string more obvious and easy to tweak.

4 years ago
(updated 4 years ago)

Added toggle-able (via button or hotkey) and auto-updating table on the right in 0.0.19:

Any env changes should be reflected in there immediately. Can be kept open separately from the main combinator UI.
(crazy values in the image are from serpent module test suite)

4 years ago

Oh, forgot the "clear env" button, can probably be added for right-click to the same one.

4 years ago

Oh, forgot the "clear env" button, can probably be added for right-click to the same one.

Fixed in 0.0.20.

4 years ago

One interesting thing about such env-table, is that it can eliminate the need for all other debug functionality, as you can just set globals to be printed there and get insights into code that way.

4 years ago
(updated 4 years ago)

thanks! Even though the variable list is in its own window, I think it would be best if it auto closed when I closed the main combinator gui.

Although maybe theres some debug purpose where you would want it to stay open?

Either way, it is not currently able to be closed using escape. Same for the help window

4 years ago

is there a difference between the x in the top left and the close in the bottom right?

4 years ago

Either way, it is not currently able to be closed using escape. Same for the help window

Yeah, default escape hotkey only works on one window, which is main one here.
There is a separate Ctrl-Q mod hotkey to close them all though.

is there a difference between the x in the top left and the close in the bottom right?

Nope, none whatsoever, but I think extra button next to others is probably nice, though I just always use hotkeys instead - way faster.

4 years ago

oh I didn't know about the ctrl-Q hotkey!
Thanks

4 years ago
(updated 4 years ago)

Check out Ctrl+S, Ctrl+F and Ctrl+Enter as well. They all should be rebindable in factorio Control menu too.
One quirk is that factorio disables all hotkeys when editing text, but Esc can rather easily unfocus that, and then they all work again.

4 years ago

Ctrl+F does not work for me. In settings its listed as Unknown key:"controls.mlc-vars". And can you please add it to the tooltip of the vars window in the main gui because I also didn't know about that one

4 years ago

Oh, right, forgot about that, iirc other keys have tooltips.
Also, there's a quick list of them in Help window.
"Unknown key" thing is probably me forgetting to update locale somewhere too, oops.

Also, it's technically possible to close all other GUIs on Esc, which I think I made kinda unclear above - Esc still runs on_gui_close hook, and all other windows can be closed from there.
But idk if it's worth it - separate variable window might indeed be nice to keep around for debugging or even network monitoring (it persists on save/load too!), though maybe an option can be added if that's too annoying. Or maybe a separate "close them all" button even.
Help window is probably a non-issue though, as I doubt player(s) will ever look at it more than once, if even that :)

4 years ago

Ctrl+F does not work for me.

Hm, and it actually doesn't work without main gui open, should probably fix that too.
Fixed other things in 0.0.22, I think.

4 years ago
(updated 4 years ago)

Also, there's a quick list of them in Help window

That would mean I would have to actually read the manual, though. sheesh, high expectations much?

Help window is probably a non-issue though, as I doubt player(s) will ever look at it more than once, if even that :)

What?! No! I've totally memorized it!

Having only the main gui close on escape by default is fine, now that I know about ctrl-Q exists. although I might rebind stuff.
close everything -> esc
close just main -> shift-esc (ctrl-Q does not work while typing)

4 years ago

close everything -> esc
close just main -> shift-esc (ctrl-Q does not work while typing)

hmm can't rebind close only main... oh well I've fine with just closing everything

4 years ago

Hm, and it [Ctrl-F] actually doesn't work without main gui open, should probably fix that too.

Fixed that in 0.0.23.

4 years ago

close everything -> esc
close just main -> shift-esc (ctrl-Q does not work while typing)

That's tricky, because Esc key is not of this mod, but like one of the most basic Factorio keys, opening main menu, closing all other guis, etc.
Also note that given that there're only two relevant windows, and Ctrl-F works everywhere now, you can just close main one with Esc and toggle side one with Ctrl-F anytime (it should remember uid of the last combinator it tracked).

4 years ago
(updated 4 years ago)

like one of the most basic Factorio keys, opening main menu, closing all other guis, etc.

Bah I like living on the edge. I can see why you didn't make that the default.
In my limited testing it seems to work for me though

New response