return an array of ALL entities of specific type(assemblers)

Place to get help with not working mods / modding interface.
darkrail
Burner Inserter
Burner Inserter
Posts: 7
Joined: Wed Apr 13, 2016 8:55 pm
Contact:

return an array of ALL entities of specific type(assemblers)

Post by darkrail »

I was looking around the modding api, and I can't seem to find a function that allows me to return an array with all entities of a type, assemblers, furnaces and so forth, have I missed something? Or is the LuaSurface "find_entities_filtered" the way I have to do it?
Rseding91
Factorio Staff
Factorio Staff
Posts: 15896
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: return an array of ALL entities of specific type(assemblers)

Post by Rseding91 »

darkrail wrote:I was looking around the modding api, and I can't seem to find a function that allows me to return an array with all entities of a type, assemblers, furnaces and so forth, have I missed something? Or is the LuaSurface "find_entities_filtered" the way I have to do it?
It is.
If you want to get ahold of me I'm almost always on Discord.
darkrail
Burner Inserter
Burner Inserter
Posts: 7
Joined: Wed Apr 13, 2016 8:55 pm
Contact:

Re: return an array of ALL entities of specific type(assemblers)

Post by darkrail »

alright thanks, if I understand correctly I can go through each of the luasurfaces with a loop right? Also where can I find the max size of the areas used for the find entities
User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: return an array of ALL entities of specific type(assemblers)

Post by prg »

Code: Select all

for chunk in surface.get_chunks() do
    local entities = surface.find_entities_filtered{name="my-entity", area={{chunk.x*32, chunk.y*32}, {(chunk.x+1)*32, (chunk.y+1)*32}}}
    for _, entity in pairs(entities) do
        --stuff
    end
end
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
darkrail
Burner Inserter
Burner Inserter
Posts: 7
Joined: Wed Apr 13, 2016 8:55 pm
Contact:

Re: return an array of ALL entities of specific type(assemblers)

Post by darkrail »

prg wrote:

Code: Select all

for chunk in surface.get_chunks() do
    local entities = surface.find_entities_filtered{name="my-entity", area={{chunk.x*32, chunk.y*32}, {(chunk.x+1)*32, (chunk.y+1)*32}}}
    for _, entity in pairs(entities) do
        --stuff
    end
end
Ah, thank you very much I will try that
Post Reply

Return to “Modding help”