I see that in the modding api, there seems to be no way of replacing objects with new one?
How one might accomplish that? Collect a list of all tiles/entities?
I want to write a migration file, but it looked like I can't do that in any efficient manner since I didn't bother to put the tiles in a list.
Migration Strategy
Re: Migration Strategy
In a migration JSON file:
Pretty much does what it sounds like.
Code: Select all
{
"entity":
[
["inserter", "fast-inserter"],
["transport-belt", "fast-transport-belt"]
],
"tile":
[
["dirt", "grass"]
]
}
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
Re: Migration Strategy
Thanks, but it seems you can only replace entity with entity, and tile with tile from your example:prg wrote:In a migration JSON file:
Pretty much does what it sounds like.Code: Select all
{ "entity": [ ["inserter", "fast-inserter"], ["transport-belt", "fast-transport-belt"] ], "tile": [ ["dirt", "grass"] ] }
I was thinking:
1. FInd all tiles with "accelerator"
2. Replace these tiles with entity "accelerator_accumulator"
Or
1. Find all tiles with "accelerator"
2. Place entity "accelerator_accumulator" on top of tiles
Re: Migration Strategy
Right.kiba wrote:Thanks, but it seems you can only replace entity with entity, and tile with tile from your example:
There always has to be a tile at a position, replacing a tile with an entity wouldn't make sense.kiba wrote:I was thinking:
1. FInd all tiles with "accelerator"
2. Replace these tiles with entity "accelerator_accumulator"
kiba wrote:Or
1. Find all tiles with "accelerator"
2. Place entity "accelerator_accumulator" on top of tiles
Code: Select all
for _, surface in pairs(game.surfaces) do
for chunk in surface.get_chunks() do
for x = 0, 31 do
for y = 0, 31 do
local pos = {chunk.x * 32 + x, chunk.y * 32 + y}
if surface.get_tile(pos[1], pos[2]).name == "dirt" then
surface.create_entity{name="inserter", position=pos} --might also want to specify a force here
end
end
end
end
end
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
Re: Migration Strategy
Thanks for the code. I now have an idea of what to do.
Re: Migration Strategy
I wasn't sure about the copyright status of short snippets modified from a forum.
So I am linking the relevant forum post tin this thread. I doubt I will get sued for code snippets that's meant to be used by me and others(that's just silly!), but I am paranoid about this.
So I am linking the relevant forum post tin this thread. I doubt I will get sued for code snippets that's meant to be used by me and others(that's just silly!), but I am paranoid about this.