[Rseding] [for 0.16] Item used to build an entity doesn't respect order

This subforum contains all the issues which we already resolved.
User avatar
mickael9
Fast Inserter
Fast Inserter
Posts: 112
Joined: Mon Mar 14, 2016 4:04 am
Contact:

[Rseding] [for 0.16] Item used to build an entity doesn't respect order

Post by mickael9 »

This bug is about the way the game selects which item is needed for building a specific entity (eg, when placing a ghost).

I already discussed this with Rseding91 on #factorio and was told that the game used the first item in the prototype sort order (group, subgroup, order key).

Unfortunately, this isn't how the game does it actually. I've done a bit of research and made a few hypothesis on how the items are actually sorted:
  • By order of appearance in data.raw (unlikely since data.raw is indexed by prototype type)
  • By item type and order of appearance
  • By item type and name
  • By item name
I set up a test data.lua that creates a few items so that the result will tell us which hypothesis seems to be the good one:
data.lua
Using this code, we try to ghost-build a dummy-entity:

Code: Select all

/c game.player.surface.create_entity{name = 'entity-ghost', inner_name = 'dummy-entity', position = { game.player.position.x, game.player.position.y - 1 }, force = game.forces.player }
And we get this:
alert.png
alert.png (29.93 KiB) Viewed 2069 times
The expected result would be a "5" icon (for item-5)
So it would seem that the game actually uses the first item in ascending name order which is quite inconvenient if you want to control which item gets used.
Attachments
wrong-order_0.0.1.zip
(35.41 KiB) Downloaded 88 times
Rseding91
Factorio Staff
Factorio Staff
Posts: 14250
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Item used to build an entity doesn't respect order

Post by Rseding91 »

Thanks for the report. I plan on changing it but not at this stage for 0.15 I'll do it for 0.16.
If you want to get ahold of me I'm almost always on Discord.
kovarex
Factorio Staff
Factorio Staff
Posts: 8207
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: [Rseding] Item used to build an entity doesn't respect order

Post by kovarex »

What is the reason to build one entity with two items anyway. What if we just disallowed it completely? It would definitely solve this bug wouldn't it? :)
User avatar
mickael9
Fast Inserter
Fast Inserter
Posts: 112
Joined: Mon Mar 14, 2016 4:04 am
Contact:

Re: [Rseding] Item used to build an entity doesn't respect order

Post by mickael9 »

If you have items that have different "variants" (different item name/type) then it avoids creating dummy entities to match each variant of the item.
You can also control which item a construction robot will use to build an entity, while allowing the player to use a different item to place it.

For instance, my portable chests mod features portable chest items that can be placed as containers (entities), but I have two variants of the chest item: an "empty" variant (which is just a item-with-tags) and a normal variant (item-with-inventory).

The idea here is that the player should be able to build the container entity using the item-with-inventory while construction robots can only use the item-with-tags variant. If I only had one variant (item-with-inventory), the robots would take any item, even if it has items in its inventory, and use that to build a newly created ghost, loosing all items in the item's inventory.
Post Reply

Return to “Resolved Problems and Bugs”