Page 1 of 1

Please explain to me: Prototype/ItemWithEntityData

Posted: Sun Jan 31, 2021 7:29 pm
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?

Re: Please explain to me: Prototype/ItemWithEntityData

Posted: Sun Jan 31, 2021 8:54 pm
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.

Re: Please explain to me: Prototype/ItemWithEntityData

Posted: Mon Feb 01, 2021 12:40 am
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.