Page 1 of 1
Unable to query for ghosts of stone bricks in an area
Posted: Mon Jun 10, 2019 5:06 pm
by RockDeicide
I'm using the following script to look for ghosts of stone bricks and concrete around the player; it has no issues finding concrete ghosts, but not stone bricks.
Code: Select all
local surface = game.player.surface
local pos=game.player.position
local size = 10
local entities = surface.find_entities({{pos.x-size, pos.y-size},{pos.x+size, pos.y+size}})
local count = 0
for key, entity in pairs(entities) do
if entity.type == "tile-ghost" and (entity.ghost_name == "stone-brick" or entity.ghost_name == "concrete") then
count = count + 1
end
end
game.player.print(count)
I noticed that Closest First wasn't reacting to stone brick since 0.16 (I think), but I thought it was some bug with the mod all this time.
Re: Unable to query for ghosts of stone bricks in an area
Posted: Mon Jun 10, 2019 5:12 pm
by Loewchen
I believe the tile is stone-path while the item is stone-brick.
Re: Unable to query for ghosts of stone bricks in an area
Posted: Mon Jun 10, 2019 5:29 pm
by RockDeicide
Huh, is this a relic of a past design process? Surely the tile and the item should be named the same, to avoid confusion with mods like Closest First that rely on the consistency between the name of the entity and the item. Especially considering that stone path seems to be the odd one out: all of the other tiles and entities are already named after their items.
Re: Unable to query for ghosts of stone bricks in an area
Posted: Mon Jun 10, 2019 7:39 pm
by eradicator
RockDeicide wrote: Mon Jun 10, 2019 5:29 pm
that rely on the consistency between the name of the entity and the item.
Any mod that relies on this is broken by design and should be trashed or rewritten from scratch. Name equality is a mere readability convention and the relation between item and entity does not even have to be bijective. The API offers lists of both entities placed by an item and items that can place an entity.
Re: Unable to query for ghosts of stone bricks in an area
Posted: Mon Jun 10, 2019 11:46 pm
by Bilka
RockDeicide wrote: Mon Jun 10, 2019 5:29 pm all of the other tiles and entities are already named after their items.
You must be new to modding, making a statement with such certainty. Here are some other examples of things like the stone path: both hazard concrete items are just named (refined) hazard concrete, but the tiles they place are named (refined) hazard concrete right and (refined) hazard concrete left. Until 0.17, the landfill item placed grass-1. The rail item does not place rails, it places straight rails and curved rails.
Anyway, the point of the above exercise is that you should use the placeable result of items and the placeable by of entities, as eradicator says.