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] Train Stop Name Pull

2 years ago

I am working on optimizing UPS on my pyanodon base and was interested in replacing my current train stop combinator setup with a single moon logic combinator. My first step is to pull the train stop name using the combinator, is this possible? I am using LTN so there is a redwire attached to the input lamp rather than the actual train stop.

Ex. my train stops are named "Iron Plate - Iron Ore Drop" and I want to pull the "Iron Ore" and convert that string to the actual item. Currently I have to manually plug in the Iron Ore into an arithmatic combinator (Input "Iron Ore" * -1; Output "Iron Ore" to set the request for each stop.

2 years ago

Signals on input wires are obviously just numbers, so no strings will be there directly.

But I think there are two ways to implement what you want:

  • Trace input wire(s) to when they hit closest Train Stop and read its name.

  • Trace input wire(s), and maybe only direct connections of these, to LTN combinator, and then interface with LTN mod via some RCON API (which it likely exposes for other mods) to get station name and maybe other useful info there.

Both seem to be too use-case specific and relatively complex for the me to implement here atm, but I think you can do both via hidden factorio api access, via "_api" global var. FAQ should have a bit more info on that, and people in other threads here seem to make use of it for many other things.

That should give you access to this API: https://lua-api.factorio.com/latest/
Where you can get current Moon Logic combinator LuaEntity as e.g. _api.global.combinators[uid].e and that should have connected wires accessible on it, which can be queried for entities on the other end of them.
(or if wires can be complicated, LTN has no good API for this, etc etc - maybe just look for "nearby train stop", kinda like person was doing in the thread here - https://mods.factorio.com/mod/Moon_Logic/discussion/6149e104ba18715822e1d5aa )

Probably obvious, and as FAQ should also mention, this is a very powerful API through which you can break stuff rather easily, if not careful, as you are essentially writing your own mod at this point :)

2 years ago

Maybe also worth mentioning that you can probably find creative ways even without going through factorio api's (though that shouldn't be difficult at all either), like maybe setting resource ID and count values as signals via constant combinator, or maybe LTN sends some signals that can be interpreted to that effect too.

Just wanted to say that I'm likely missing a lot of things about specific setup you want, and those two options are just first generic things that come to mind, which aren't necessarily the best way to go about it in your case.

2 years ago

Very helpful, thank you! I think what I will do is just create a simple mod to grab and parse the name to output the desired item when placed.

On my pickup stations I have a lamp that lights different colors depending on the current capacity (red < 1 train load, yellow <= 2, blue <=4, and green >4). This requires 6 arithmetic combinators and 2 deciders. On the stations I also have a timer that sends a signal to a speaker if the station is red for greater than 5 minutes. There are approximately 480 of these stations. In your opinion would a single moon logic combinator at each location to replace these have a positive or negative effect on UPS?

2 years ago

Hm, I don't know.

If MLCs code runs on every tick, I think it'd be negative, but have no numbers to reason about it, really.
It's just that running a bunch of lua lines has to be less efficient than likely very optimized C++ code implementing built-in combinators.

With sufficient delay= it can probably change, so if that's a goal/concern, I'd probably try making some rough "same amount of lua operations" benchmark-code, and copy-paste like 100 or 1K running processing-chains of each type into a field, measure what happens, maybe when you're away from them, so that any rendering stuff doesn't factor into it.

Never really benchmarked and optimized code here myself, beyond basic common sense like "use table for lookups", as I never built anything on that scale in factorio, so maybe treating this as an optimization tool is entirely erroneous too, unfortunately.

2 years ago

Setting the delay is a good idea, there is no reason for these to be updated every tick. Every 10th or so would probably be sufficient. Are there any events that would reset the count of all of the delays back to 0? I know when I update any of the current mods some mods seem to rerun their initialization functions. My thought would be to spread all of the calculations over the 10 ticks so there wouldn't be a stutter every 10th tick.

2 years ago
(updated 2 years ago)

You just need to set delay= variable in the environment on every tick to have combinator sleep that time until next code run, so it's not some kind of option that can be meaningfully reset, I think.
Times until next code run are stored in mod globals, which shouldn't ever reset afaik, so don't think it should be a problem either way.
Maybe some mods reset their state stuff on changes to not worry about keeping it compatible between versions, e.g. if it's not very important anyway.

Also, if you want to not bother executing stuff until some "train is here" signal, there're "irq" variables (see in-game help box), which can likely be good for UPS, though not actually intended for that either, mostly there for convenience of avoiding periodic checks with long sleeps.

2 years ago

Thinking through some more, 600 ticks would be better. Making it run using 500 + random 1-100 would solve the issue if they ever were reset.

2 years ago

Oh, yeah, and if sleeping for e.g. 600 ticks between checks is fine, I imagine using "irq" things would likely be counter-productive UPS-wise, as iirc it checks signal on every tick, and intended for a kind of instant response/wakeup.

New response