Page 1 of 1
return an array of ALL entities of specific type(assemblers)
Posted: Wed Apr 13, 2016 9:15 pm
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?
Re: return an array of ALL entities of specific type(assemblers)
Posted: Wed Apr 13, 2016 9:16 pm
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.
Re: return an array of ALL entities of specific type(assemblers)
Posted: Wed Apr 13, 2016 9:25 pm
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
Re: return an array of ALL entities of specific type(assemblers)
Posted: Wed Apr 13, 2016 9:30 pm
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
Re: return an array of ALL entities of specific type(assemblers)
Posted: Wed Apr 13, 2016 9:51 pm
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