LuaSurface::find_entity returns no-collision entity
Posted: Sun Mar 05, 2017 9:41 am
Request:
LuaSurface::find_entity can find entities that have zero-sized collision box (collision_box = {{0, 0}, {0, 0}}), e.g. item-request-proxy
This thing has bugged me for quite some time: we have to use LuaSurface::find_entities_filtered to get the entity that we know its name and exact position, but LuaSurface::find_entity cannot get it for us.
At the end, we have to do this
instead of the expected, clean way
We do this not just for item-request-proxy, but most of the time, we do this for our custom entities (e.g. combinator) with zero-sized collision box so players cannot select them in normal way.
LuaSurface::find_entity can find entities that have zero-sized collision box (collision_box = {{0, 0}, {0, 0}}), e.g. item-request-proxy
This thing has bugged me for quite some time: we have to use LuaSurface::find_entities_filtered to get the entity that we know its name and exact position, but LuaSurface::find_entity cannot get it for us.
At the end, we have to do this
Code: Select all
local x = position.x
local y = position.y
local arr = surface.find_entities_filtered{area = {{x - 0.1, y - 0.1}, {x + 0.1, y + 0.1}}, name = "item-request-proxy", force = force, limit = 1}
if #arr > 0 then
local item_request_proxy = arr[1]
-- We can finally work on the proxy!!
Code: Select all
local item_request_proxy = surface.find_entity("item-request-proxy", position)
if item_request_proxy then
-- blah blah blah
end