What types of entity have a unit_number? Is it just units? Or other things too?
On a similar topic, is it possible to get a LuaEntity by its unit number, or would I need to keep a table of [entity.unit_number] = entity?
Entity unit_number
Re: Entity unit_number
Anything that can belong to a force also has a unit number.
No, you need to build your own table.
No, you need to build your own table.
Re: Entity unit_number
You don't need the uid, but
You can make your own uid for entities such as
You can make your own uid for entities such as
Code: Select all
local uid = generate_uid()
global.holders[uid] = {entity = entity, uid = uid}
Code: Select all
function generate_uid()
local last_uid = global.last_uid or 0
local new_uid = last_uid +1
global.last_uid = new_uid
return new_uid
end
Re: Entity unit_number
This doesn't help, for instance if you have a `entity_died` event, and you want to lookup the entity in your global list, how is this uid useful?darkfrei wrote: ↑Wed Oct 28, 2020 8:10 amYou don't need the uid, but
You can make your own uid for entities such asCode: Select all
local uid = generate_uid() global.holders[uid] = {entity = entity, uid = uid}
Code: Select all
function generate_uid() local last_uid = global.last_uid or 0 local new_uid = last_uid +1 global.last_uid = new_uid return new_uid end
Unit number if useful because you can be given an entity from any event, and then easily and reliably lookup its data using the unit_number as the key.
Also you can get a better uid, reliable, by using https://lua-api.factorio.com/latest/Lua ... _destroyed, which works for all entities
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Entity unit_number
Can you ellaborate how that is "better"? So far i assumed that it causes additional overhead and thus is a waste on anything that already has a unit_number.Klonan wrote: ↑Wed Oct 28, 2020 9:59 amAlso you can get a better uid, reliable, by using https://lua-api.factorio.com/latest/Lua ... _destroyed, which works for all entities
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: Entity unit_number
I mean, better than using Lua to assign a counteradicator wrote: ↑Thu Oct 29, 2020 1:22 amCan you ellaborate how that is "better"? So far i assumed that it causes additional overhead and thus is a waste on anything that already has a unit_number.Klonan wrote: ↑Wed Oct 28, 2020 9:59 amAlso you can get a better uid, reliable, by using https://lua-api.factorio.com/latest/Lua ... _destroyed, which works for all entities