Sandboxed LuaCombinator

by IWTDU

Program combinators with lua. Now there is a version with outputs isolated from inputs!

Content
4 years ago
0.17 - 0.18
17
Circuit network
Owner:
IWTDU
Source:
N/A
Homepage:
https://forums.factorio.com/viewtopic...
License:
CC BY-SA 4.0
Created:
4 years ago
Latest Version:
0.4.1 (4 years ago)
Factorio version:
0.17 - 0.18
Downloaded by:
17 users

Based on OwnlyMe's LuaCombinator 2 mod. https://mods.factorio.com/mod/LuaCombinator2
Main differences:
- Less overhead when using circuit network
- No cheating, very restricted access to game api
- There is a version with outputs isolated from inputs

Currently accessible game api elements:
serpent.block
game.tick
game.item_prototypes
game.recipe_prototypes

Multiple inputs/outputs

Starting from 0.4.0 you can place additional inputs and outputs. Craft and place them on tiles adjacent to combinator (max 4 positions per combinator for both combinator types). You will see "Assigned" floating text if you are doing it right.
Previously there was api for only one input and one output, so now there is a new api (old still works, now through new one). This new api is:
- outputs table, use it like outputs[2]['signal-B'] = 10
where 2 is output number (1 is combinator's output, then 2,3, and so on are additional outputs by built order)
#outputs is output count including built-in output
you can reset output to desired state by assignment like outputs[2] = { ['signal-C'] = 10 }
- inputs table, indexed same as outputs
examples:
local A = inputs[1].red['signal-A']
local inp_count = #inputs

-- sum everything on green input 2 and set as S signal to output (once in game second)
local g = inputs[2].green
local s = 0
for k,v in pairs(g) do
s=s+v
end
output['signal-S'] = s
delay=60

Bugs, errors

Please, report bugs instead of hoping that I know about them. Even "obvious" bugs may not be noticed by me because often there is more fun in programming mod than playing with it.

Code on this mod's combinators can only interface game world with reading and sending signals from/to connected circuit networks. Every combinator code executed isolated from game, mods and other combinators namespaces. Otherwise you can use all power of lua for processing that signals (what is the main thing required from combinator). Global variables are preserved always, no need for 'var', 'var' now is just a variable like any other combinators variable.

Most of code for LuaCombinator2 should work, including examples from it's page.