Unable to query for ghosts of stone bricks in an area

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
RockDeicide
Burner Inserter
Burner Inserter
Posts: 17
Joined: Sat Dec 29, 2018 9:25 am
Contact:

Unable to query for ghosts of stone bricks in an area

Post 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.

Loewchen
Global Moderator
Global Moderator
Posts: 8308
Joined: Wed Jan 07, 2015 5:53 pm
Contact:

Re: Unable to query for ghosts of stone bricks in an area

Post by Loewchen »

I believe the tile is stone-path while the item is stone-brick.

RockDeicide
Burner Inserter
Burner Inserter
Posts: 17
Joined: Sat Dec 29, 2018 9:25 am
Contact:

Re: Unable to query for ghosts of stone bricks in an area

Post 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.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Unable to query for ghosts of stone bricks in an area

Post 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.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Bilka
Factorio Staff
Factorio Staff
Posts: 3129
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Unable to query for ghosts of stone bricks in an area

Post 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.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Post Reply

Return to “Modding discussion”