Lua: Does an entity change it

Place to get help with not working mods / modding interface.
User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12889
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Lua: Does an entity change it

Post by ssilk »

My problem: I have a "general table" of all entities, that my mod should maintain. That list should also survive saves, so it is a global table.

From that table I want to make "fast" tables, that can be accessed by triggered events.

About like so:

Code: Select all

...
entityInfo = {
  entity = entity,
  state = calculateSomeState(entity),
...
}
...
table.insert(gobals.entitiestable[force.name], entityInfo)  -- adds one entityInfo to the global table
...
table.insert(my_fast_table[entity][entityInfo.state], entityInfo.entity) -- adds that entity to the "fast" table
...
The problem comes up, when I an entity is destroyed or changes. I need to remove it either fomr the globals.entitytable or from my_fast_table.
In both cases I want to lookup to the same entry in the other table.

So my idea about this was, that all entities are not added to a sorted list (1, 2, 3...) but to a hashed-table.
The problem is then: How do I get a useful hash?

My idea for that looks currently like so:

Code: Select all

...
entityInfo = {
  entity = entity,
  state = calculateSomeState(entity),
...
}

entitiyInfo.hash = tostring(entitiyInfo.entity) -- entitiyInfo.hash is now something like table: 0x123e47129

...
gobals.entitiestable[force.name][entityInfo.hash] = entityInfo  -- adds one entityInfo to the global table
...
my_fast_table[entity][entityInfo.state][entityInfo.hash] = entityInfo.entity -- adds that entity to the "fast" table
...
The question is: If now a new entity comes, that is in reality one, that is already existing in my globals table, will it have the same hash?
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...
User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: Lua: Does an entity change it

Post by Adil »

No, it doesn't. You're just converting an object reference into text, at different time a game might give you different reference to the same object.
Most entities have unit_number these days, which is unique identifier for them.
I also don't quite get why the second table is titled 'fast'.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12889
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Re: Lua: Does an entity change it

Post by ssilk »

Thanks so far, Adil.
Adil wrote: I also don't quite get why the second table is titled 'fast'.
Because the post is - however - posted before it should have been posted. I'm sorry, the right post is viewtopic.php?f=25&t=33905
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...
Locked

Return to “Modding help”