in global.ControlList the first entry is an invalid LuaEntity. My Control is on pos 2.
I added a new function:
function getValidControl()
for i,ctrl in pairs(global.ControlList) do
if(global.ControlList[i].valid) then
return i
end
end
return 0
end
and use this in function CreateProvider(loc)
local control = global.ControlList[getValidControl()]
local pos = control.position
local surface = control.surface
local force = control.force
local entity = surface.create_entity{name=loc.entity.name.."-power",position=pos,force=force}
loc.provider = entity
end
not sure what will happen if i delete all controls to, but at least i can place and use your trains again