I've been making mod for mass placing walls, turrents, poles, radars etc. just for practice and fun (yeah yeah I know...)

For this I use for now the function:
Code: Select all
function operation_Wall2(pStart, pFinish)
local start=pStart or -900
local finish=pFinish or 900
local distance=30
local radarDist=7
local bigPolesCount=0
if start > finish then
bigPolesCount = start - finish
else
bigPolesCount = finish - start
end
bigPolesCount = math.floor(bigPolesCount / distance)
local pos = {}
local pos2 = {}
for i=0, bigPolesCount, 1 do -- top left to top right
pos = {x=(start + (i * distance)), y = start}
game.player.teleport{x=pos.x, y=pos.y-3} -- useless, it's all in one tick :)
operation_removeEverything(pos, 20)
-- Big Pole
if (game.canplaceentity{name="big-electric-pole", position = pos}) then
game.createentity{name = "big-electric-pole", position=pos, force=game.forces.player}
end
-- RADAR
pos.x = pos.x-3
if i%radarDist==0 and (game.canplaceentity{name="radar", position = pos}) then
game.createentity{name = "radar", position=pos, force=game.forces.player}
end
pos.x = pos.x+3
end
-- more similar IFs here for other walls
end
function operation_removeEverything(position, radius)
local toolArea = radius or 32
local entities = game.findentities{{position.x - toolArea, position.y - toolArea}, {position.x + toolArea, position.y + toolArea}}
for i, entity in ipairs(entities) do
if entity ~= nil and entity.valid and entity.name~="player" then
entity.destroy()
end
end
end
When it's placed and I try to mine one of the new poles then game crashes.
When it's placed and I save the game, then try to load it, then I get Deserialization error, item id xxxx not exists...
Is there something I don't know about using createentity?
In other tries I didn't create poles, just radars, walls, turrets, and then placed poles by hand... and same error again when mining/loading save.
I even let the game running for some time (waited on debug console for all numbers to settle (Entities counters, connections counter), but it didn't help

Any suggestions, or is it just some bug in game?