Adding in data to entities

Place to get help with not working mods / modding interface.
Senoro
Manual Inserter
Manual Inserter
Posts: 3
Joined: Fri Sep 02, 2016 3:49 pm
Contact:

Adding in data to entities

Post 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

Code: Select all

entity.connected_entity
and it refers to another entity?

And help would be appreciated. Thanks
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Adding in data to entities

Post 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}
}
Senoro
Manual Inserter
Manual Inserter
Posts: 3
Joined: Fri Sep 02, 2016 3:49 pm
Contact:

Re: Adding in data to entities

Post 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?
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Adding in data to entities

Post 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!")
Senoro
Manual Inserter
Manual Inserter
Posts: 3
Joined: Fri Sep 02, 2016 3:49 pm
Contact:

Re: Adding in data to entities

Post by Senoro »

Ahh, that´s a good idea. I guess Ill use that than. Thanks a lot
Post Reply

Return to “Modding help”