0.16.51 - Multiple entities on same position not found by API call
Posted: Mon Nov 05, 2018 3:58 pm
When there are 2 entities on the same position using surface.find_entities_filtered with position specified only returns 1, however using an area of -/+ 0.00001 returns both. The 2nd entity is created on to the same position as the first, but has custom flags on its prototype.
I have attached a cut down version of the mod and ingame script to demonstrate the issue. When the 2
The custom prototype is a hidden light entity with the below as the mod code in data-updates.lua
The ingame script code to create the entities with the exact same position
The ingame script code to demonstrate the issue. Both commands should return the power pole and light, however the position command only returns the power pole.
As a side note use of surface.find_entity with the "hiddenlight" name and the position of the power pole will find the hiddenlight entity.
I have attached a cut down version of the mod and ingame script to demonstrate the issue. When the 2
The custom prototype is a hidden light entity with the below as the mod code in data-updates.lua
Code: Select all
local lightRange = 5
local hiddenLight = table.deepcopy(data.raw["lamp"]["small-lamp"])
hiddenLight.name = "hiddenlight"
hiddenLight.collision_box = nil
hiddenLight.collision_mask = nil
hiddenLight.selection_box = nil
hiddenLight.flags = {"not-blueprintable", "not-deconstructable", "placeable-off-grid", "not-on-map"}
hiddenLight.selectable_in_game = false
hiddenLight.picture_off = {
filename = "__base__/graphics/entity/small-lamp/lamp.png",
width = 0,
height = 0
}
hiddenLight.picture_on = {
filename = "__base__/graphics/entity/small-lamp/lamp.png",
width = 0,
height = 0
}
hiddenLight.light = {intensity = 0.6, size = lightRange, color = {r=1.0, g=1.0, b=1.0}}
hiddenLight.energy_usage_per_tick = "0W"
hiddenLight.energy_source.render_no_network_icon = false
hiddenLight.energy_source.render_no_power_icon = false
data:extend({hiddenLight})
Code: Select all
/c
local surface = game.player.surface
local playerPositionOffset = {game.player.position.x + 2, game.player.position.y + 2}
local powerPoleEntity = surface.create_entity{name="small-electric-pole", position=playerPositionOffset}
surface.create_entity{name="hiddenlight", position=powerPoleEntity.position}
Code: Select all
/c
local surface = game.player.surface
for _, mainEntity in pairs(surface.find_entities_filtered{type="electric-pole"}) do
for lightEntityIndex, lightEntity in pairs(surface.find_entities_filtered{ position = mainEntity.position }) do
game.print("light position: " .. lightEntity.name .. " - " .. lightEntity.type .. " pos: " .. lightEntity.position.x .. ", " .. lightEntity.position.y)
end
end
for _, mainEntity in pairs(surface.find_entities_filtered{type="electric-pole"}) do
for lightEntityIndex, lightEntity in pairs(surface.find_entities_filtered{ area = {{mainEntity.position.x-0.0001, mainEntity.position.y-0.0001}, {mainEntity.position.x+0.0001, mainEntity.position.y+0.0001}}}) do
game.print("light area: " .. lightEntity.name .. " - " .. lightEntity.type .. " pos: " .. lightEntity.position.x .. ", " .. lightEntity.position.y)
end
end
As a side note use of surface.find_entity with the "hiddenlight" name and the position of the power pole will find the hiddenlight entity.