It would be nice to have a unique identifier for each entity, for example entity.id, similar to player.index. My current work around is to concat strings together like so:
Code: Select all
-- Return a string representing the unique entity id
function entity_id(entity)
if not entity then return nil end
return entity.name .. "-" .. entity.position.x .. "-" .. entity.position.y .. "-" .. entity.surface.name .. "-" .. entity.force.name
end
A couple disadvantages of this workaround:
- I don't know if it is 100% reliable, for example can two entities can have the same name, position, force name and surface name? If so this would fail.
- The returned id is longer than necessary, it would be nicer to have a uuid instead.
- String concatenation is slower: in this case it would be faster to do read 1 id property directly from memory.
- Calling entity_id(entity) is more verbose than entity.id.