LuaGameScript:get_entity_by_unit_number()
LuaGameScript:get_entity_by_unit_number()
Is there any particular reason why we are unable to get a LuaEntity from a unit_number (which would obviously fail silently for not-existing ones)?
Re: LuaGameScript:get_entity_by_unit_number()
It's an O(N) search - equivalent to you doing "for k,v in pairs(game.player.surface.find_entities_filtered{}) do if v.unit_number == ## then .. end end"
If you want to get ahold of me I'm almost always on Discord.
-
- Filter Inserter
- Posts: 841
- Joined: Mon Sep 14, 2015 7:40 am
- Contact:
Re: LuaGameScript:get_entity_by_unit_number()
It would be much better to simply store entities of interest in a custom global lookup table using unit_number as an index, no? Just add 'em each time they're deemed to be of relevance after some event and remove 'em once they've been processed satisfactorily (satisFactorio-ly?).
Re: LuaGameScript:get_entity_by_unit_number()
That would fail real quick with attempt to compare number to nilRseding91 wrote:It's an O(N) search - equivalent to you doing "for k,v in pairs(game.player.surface.find_entities_filtered{}) do if v.unit_number == ## then .. end end"
On a more serious note, What about having unit_number be an additional search parameter in find_filtered?
unit_number = true that way the returned search would only contain entities with unit_numbers.
Re: LuaGameScript:get_entity_by_unit_number()
Yes, but it's O(n) without passing essentially entire game state through the lua bridge, not to mention the creation of luaentity representations for things that previously were untouched by the lua bridge?Rseding91 wrote:It's an O(N) search - equivalent to you doing "for k,v in pairs(game.player.surface.find_entities_filtered{}) do if v.unit_number == ## then .. end end"
I seem to remember someone saying somewhere that the relevant lua representations of game objects were lazily created at least.
But if you're telling me that it would essentially be as fast and that there's very little difference - and I'm happy with both "essentially as fast" and "very little" being unquantified - that's good enough for me.