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 [fixed] Attempt to index local 'k' (a number value)

2 years ago
(updated 2 years ago)

Error:
Error while running event Moon_Logic::on_tick (ID 0)

Moon_Logic/control.lua:245: attempt to index local 'k' (a number value)
stack traceback:
Moon_Logic/control.lua:245: in function 'mlc_update_output'
Moon_Logic/control.lua:719: in function 'run_moon_logic_tick'
Moon_Logic/control.lua:763: in function <Moon_Logic/control.lua:741>

Offending Code in MLC:

out = {}
for key, value in pairs(green) do
local n = _api.game.item_prototypes[key].stack_size
out[n] = out[n] + value
end
for key, value in pairs(red) do
local n = _api.game.item_prototypes[key].stack_size
out[n] = out[n] + value
end

Then input something, like Steel

Fix:
Add

if type(k) == 'number' then break end

to line 244 in control

Don't know wether this is the optimal fix, but it works for me.

2 years ago

Indeed looks like a bug, thanks for testing and tracking it down.

I'll probably add a check on assigning the value to output table, so that out[n] = out[n] + value in the code on the combinator will raise error immediately, and it'd be more clear where such bogus key comes from.

2 years ago

Should be fixed in 0.0.74.

Simply added tostring conversion for keys in the output table, so such numeric keys should show up as regular invalid signals.
Since output table isn't special and weird yet (unlike input tables), thought to keep it that way for simplicity and to not break something else, so it's not checked on assignment in the code, only after code runs.
In retrospect, maybe it should've been special object, so that any invalid signals set there can be detected early, but probably no big deal either way.

2 years ago

Nice, thanks!

New response