Please explain to me: Prototype/ItemWithEntityData

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
User avatar
adamwong246
Fast Inserter
Fast Inserter
Posts: 148
Joined: Tue Dec 01, 2020 5:01 am
Contact:

Please explain to me: Prototype/ItemWithEntityData

Post by adamwong246 »

I'm looking for a way to store some data on an entity itself. I need this data to persist even if the item is mined.

I was told the only way of achieving this is using something like http://afforess.github.io/Factorio-Stdl ... ntity.html to store the data "outside" the entity. Then I found https://wiki.factorio.com/Prototype/ItemWithEntityData, which by it's name implies the functionality I need. But I don't see anything in the definition that allows me to persist data per-entity as well as per-item.

Is this the prototype I am looking for or am I barking up the wrong tree?

ss_Baum
Long Handed Inserter
Long Handed Inserter
Posts: 58
Joined: Wed Apr 04, 2018 10:58 am
Contact:

Re: Please explain to me: Prototype/ItemWithEntityData

Post by ss_Baum »

So on the first look it seems to me, that this is what you search. But the problem could be, that you can only use the keys, represented on the wiki. At least I don't know, how to add some. I was told, that this isn't possible.

I store additional data also in a seperate table, using the position data of the entity. this is of course not persistant over Item mining, but you could use another unique number.

So if you don't need anothe key's than they in the Prototype, it could be yours. otherwise I don't know.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3699
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Please explain to me: Prototype/ItemWithEntityData

Post by DaveMcW »

ItemWithEntityData is poorly named, it is only designed to support vehicles.

What you really want is ItemWithTags. This has a control.lua stack.tags property that allows you to store arbitrary data.

There is no entity.tags property (well there is, but only to help copy blueprint tags from ghosts). So you have to store entity data in an external table. The best practice is to index this table with entity.unit_number.

Post Reply

Return to “Modding discussion”