Migration Strategy

Place to get help with not working mods / modding interface.
Post Reply
kiba
Filter Inserter
Filter Inserter
Posts: 344
Joined: Thu Jun 11, 2015 5:32 am
Contact:

Migration Strategy

Post by kiba »

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.

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Migration Strategy

Post by prg »

In a migration JSON file:

Code: Select all

{
        "entity":
        [
                ["inserter", "fast-inserter"],
                ["transport-belt", "fast-transport-belt"]
        ],
        "tile":
        [
                ["dirt", "grass"]
        ]
}
Pretty much does what it sounds like.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

kiba
Filter Inserter
Filter Inserter
Posts: 344
Joined: Thu Jun 11, 2015 5:32 am
Contact:

Re: Migration Strategy

Post by kiba »

prg wrote:In a migration JSON file:

Code: Select all

{
        "entity":
        [
                ["inserter", "fast-inserter"],
                ["transport-belt", "fast-transport-belt"]
        ],
        "tile":
        [
                ["dirt", "grass"]
        ]
}
Pretty much does what it sounds like.
Thanks, but it seems you can only replace entity with entity, and tile with tile from your example:

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

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Migration Strategy

Post by prg »

kiba wrote:Thanks, but it seems you can only replace entity with entity, and tile with tile from your example:
Right.
kiba wrote:I was thinking:

1. FInd all tiles with "accelerator"
2. Replace these tiles with entity "accelerator_accumulator"
There always has to be a tile at a position, replacing a tile with an entity wouldn't make sense.
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
Might take a while on a large map. Not sure if this can be done in a better way.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

kiba
Filter Inserter
Filter Inserter
Posts: 344
Joined: Thu Jun 11, 2015 5:32 am
Contact:

Re: Migration Strategy

Post by kiba »

Thanks for the code. I now have an idea of what to do.

kiba
Filter Inserter
Filter Inserter
Posts: 344
Joined: Thu Jun 11, 2015 5:32 am
Contact:

Re: Migration Strategy

Post by kiba »

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.

Post Reply

Return to “Modding help”