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] unable to save when using stuff from _api in globals

3 years ago

Did you pull something from "_api" variable in the code there?
I'd suggest checking variable window on combinators to find where something with "userdata" in it might be assigned, that's likely something like factorio prototype object.

3 years ago

yes i'm pulling in data from _api shouldnt i?

Signal = _api.game.virtual_signal_prototypes[RequestedItem]
Item = _api.game.item_prototypes[RequestedItem]
Fluid = _api.game.fluid_prototypes[RequestedItem]

if Item ~= nil then
Img = "img=item." .. RequestedItem --game.print("item : [" .. Img .. "]")
ItemRequestStackSize = Item.stack_size
RequestedItem = "#" .. RequestedItem
end
if Fluid ~= nil then
Img = "img=fluid/" .. RequestedItem --game.print("fluid : [" .. Img .. "]")
RequestedItem = "=" .. RequestedItem
end
if (Signal ~= nil) and (Item == nil) and (Fluid == nil)then
Img = "img=virtual-signal/" .. RequestedItem --game.print("signal : [" .. Img .. "]")
RequestedItem = "@" .. RequestedItem
end

(i'm new to lua -10h in atm- but i'l be damn that i'll learn it before going back to infinte combinators to get something done)

small question :p
i also try to find the position of the combinator because i want to scan its surroundings. any suggestion on how i can easely find the mlc position?

3 years ago

yes i'm pulling in data from _api shouldnt i?

You totally can, but it's a full modding api, as you probably know, and as such, it's easy to break the game when using it.
(which was what I was getting at in the last question here - https://mods.factorio.com/mod/Moon_Logic/faq )

Signal = _api.game.virtual_signal_prototypes[RequestedItem]

This line (and couple more after it) would be the issue, as it's assigning unserializable C++ object collection from api to a "Signal" global.
I'd suggest using "local Signal" for everything like that, and always keeping all variables local unless you really want them to persist between code runs, and obviously never assign api objects to those few.

3 years ago

You can click small lambda-looking button at the top of the window to see all assigned globals for this combinator btw, which is the one I meant in the first post here.

3 years ago

if Item ~= nil then

I think you can safely type "if not item then" in all these if's, as in lua only two things are falsey - nil and false objects, nothing else, and pretty sure you won't ever get these returned for anything useful.

3 years ago
(updated 3 years ago)

i also try to find the position of the combinator because i want to scan its surroundings

Hm, I'd probably use _api.global.combinators[uid].e, where "uid" is the unit_number of combinator entity, which is set by lua sandbox on each run.
Should be guaranteed to be a non-nil and valid LuaEntity (for which you can get .position attr), as otherwise code on it won't be running... unless you destroy it in the same code just above, I guess :)

There might also be a LuaSurface method to lookup entity by its unit_number (unique id) quickly, but don't seem to remember off the top of my head.
(though I have like +39C fever atm, so maybe not thinking too clearly either)

3 years ago

ah ok. no nothing is assinged to userdata or alike.
ty for the tip on the 'nil'
and you just saved me from scanning the entire map in all combinators by just that one line. (noob vs pro i guess :p)

thank you very much. love the mod btw !!

3 years ago
(updated 3 years ago)

and you just saved me from scanning the entire map in all combinators by just that one line. (noob vs pro i guess :p)

Nah, it's just an internal var that this mod uses to track all of its combinators, which ofc isn't documented anywhere.
(_api.global is a per-mod global namespace, and as lua code runs within this mod's context, it has everything that this mod tracks)

Probably obvious, but don't change anything pre-existing there (unless you want to debug this mod internals) - things will start crashing :)
Adding stuff to share between all MLCs should be fine though.

Thanks. Cheers!

3 years ago

yeah not changing anything there just reading information.

tnx again.

New response