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] Can I somehow import code form other lua-controllers?

3 years ago

Is there a smart way to import helper functions that are used in multiple files? I found a way that's super clunky I add some boilplate-code to the beginning of the file which loads the combinator with all the helper functions, runs it once and then reloads the original code from a backup, but that requires annoying boilerplate and backup-combinator for every combinator I use.

3 years ago

Is there a smart way to import helper functions that are used in multiple files? I found a way that's super clunky: I add some boilplate-code to the beginning of the file which loads the combinator with all the helper functions, runs it once and then reloads the original code from a backup, but that requires annoying boilerplate and backup-combinator for every combinator I use.

3 years ago

Can see the appeal, but unfortunately this mod wasn't designed with any global stuff in mind - I only wanted more powerful and easy-to-use cominator in line with the current in-game ones, not any kind of global lua control network mod.

This can be a problem, because sharing code between combinators would ideally need remote control, reset and debugging for them, which is not implemented (kinda trivial to do, just feels very out of scope), as currently if you share any complex function among remote combinators, any bug in it will require you to go reset each one, as errors halt them, same as you'd do with stuck/broken belt line or whatever.

There's a poorly-hidden "_api" table available to lua code, which you can use for such code-sharing though, it's defined as:

sandbox_env_base._api = { game=game, script=script,
  remote=remote, commands=commands, settings=settings,
  rcon=rcon, rendering=rendering, global=global, defines=defines }

And it basically gives access to factorio modding API.

You can store code of such shared function as a string in "global" table, and have each combinator load() and run it, but note that afaik factorio does not allow saving compiled lua code in savegames (strips them and issues warnings to log), so you'd have to either load() these each time or maybe when they got stripped on savegame load.
Check out neat gvv mod to see "global" table used in this mod anytime.

As mentioned above though, this mod is not designed with such global operations in mind, and using other stuff via that "_api" hack you can totally break anything in your game, which is why it's not really mentioned anywhere, and I'd suggest only using it to maintain some sub-table under _api.global for your purposes and not touch anything else there.

3 years ago
(updated 3 years ago)

any bug in it will require you to go reset each one, as errors halt them, same as you'd do with stuck/broken belt line or whatever.

On that note, would probably be a good idea to at least add bindable hotkey for opening combinator from anywhere on the map.

3 years ago

Thanks for your response! Sounds like this might be a good fit for me, I will try it out. I have some initialisation code in place anyway to get around the reset combinators on savegame load so it should not be a problem to load() on startup.

3 years ago

On that note, would probably be a good idea to at least add bindable hotkey for opening combinator from anywhere on the map.

Added in 0.0.48+, defaults to Ctrl+E.

It kinda breaks basic game mechanics in the same way as long reach mods do, but more in line with Pushbutton and Switch Button mods, and given how often any kind of complex code breaks, might make mod less frustrating for those who might want such feature :)
Might remove the need to reuse the code in your case too, if it's only done in couple places - can just open them all and copy-paste.

3 years ago

thank you both, guys. i ve sought a way to write standart statistics in file via moonlogic controller and this topic solved my task completely. Im very grateful to you )))

New response