Page 1 of 1
Adding in data to entities
Posted: Sun Sep 04, 2016 12:51 am
by Senoro
So I´m currently working on my first mod. And in it I have entities which are connected to other entities. Now my question is, is there a way to store extra information in an entity with a new key so that I can later on call
and it refers to another entity?
And help would be appreciated. Thanks
Re: Adding in data to entities
Posted: Sun Sep 04, 2016 1:53 am
by Nexela
Not directly no.
You want to save a table in global with data from both entities.
something like this:
global.myentities={
myentity={entity1=entity,entity2=addedentity}
}
Re: Adding in data to entities
Posted: Sun Sep 04, 2016 2:24 am
by Senoro
In that case, is there an easy and efficient way of saying:
Check this table and give me the subtable, which contains this entity? Or do I just have to go throught each subtable individually?
Re: Adding in data to entities
Posted: Sun Sep 04, 2016 6:40 am
by Nexela
yes and no
Code: Select all
on_your_event
local myentity
for , entity in pairs(global.myentites) do
if event.entity=entity.entity1
then myentity=entity.entity1
break
end
end
Alternatively you could index by unit_number
to save
global.myentities[event.entity.unit_number].entity1 = event.entity)
to retrieve
myentity == global.myentities[event.entity.unit_number].entity1
if myentity then log("we are good!")
Re: Adding in data to entities
Posted: Sun Sep 04, 2016 2:41 pm
by Senoro
Ahh, that´s a good idea. I guess Ill use that than. Thanks a lot