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] Its possible to create a lua Function file?

1 year, 19 days ago

I wanted to have a lua function file, where I could code the basic function for stuff like:

cargoStationLoad()
tankStationLoad()

etc. That way, if I change something in one of them, like, fixing a bug or something, it would automatically change for them all, instead of having to go over 100+ stations and changing it manually.

1 year, 19 days ago
(updated 1 year, 19 days ago)

There's no trivial supported way to do it, as there's no shared global environment for these combinators atm - code and vars on them are supposed to be all-local.

But if you want to go into "there be dragons" territory, can use kinda-hidden "_api" var (see also FAQ on it), which you can use to pull code from any specific combinator (e.g. dedicated one in the corner, only used for templating), via something like _api.global.combinators[uid].code.

You can then turn that code string into a lua function (or code object) via lua's load(), and I think best place to store those is probably under some custom table that you can create under _api, e.g. _api.my_funcs = {}.
But anywhere those are used, make sure to check if not _api.my_funcs then ...(load those from somewhere)... end, because they'll be wiped on save/load.
And also maybe add/check a "code version" var somewhere, for reloading it on changes.

"wiped on save/load" is (or was?) a limitation in factorio save/load system, which doesn't allow to serialize lua code objects, so this mod also does load() on all combinator code strings when game is loaded, and you'd probably need to do this for any such shared funcs as well.
I'm not sure if maybe these days this limitation might no longer exist - didn't check - and if it doesn't, then you can also probably save code objects more permanently under _api.global.

1 year, 19 days ago

Thank you very much for the fast and concise reply. Gonna give that a try!

New response