return an array of ALL entities of specific type(assemblers)
return an array of ALL entities of specific type(assemblers)
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?
Re: return an array of ALL entities of specific type(assemblers)
It is.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?
If you want to get ahold of me I'm almost always on Discord.
Re: return an array of ALL entities of specific type(assemblers)
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
Re: return an array of ALL entities of specific type(assemblers)
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!
Re: return an array of ALL entities of specific type(assemblers)
Ah, thank you very much I will try thatprg 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