Page 1 of 1
[0.15.16] luadoc for LuaEntity.unit_number
Posted: Tue May 30, 2017 8:53 am
by folk
Hi,
So the luadocs for
http://lua-api.factorio.com/latest/LuaE ... nit_number is a bit unclear;
Are unit_numbers universally unique for the lifetime of a whole game?
That is to say, if one was destroyed, is there ever any chance that another LuaEntity will have the unit_number of the destroyed one?
Thank you!
Re: [0.15.16] luadoc for LuaEntity.unit_number
Posted: Tue May 30, 2017 8:57 am
by posila
folk wrote:Are unit_numbers universally unique for the lifetime of a whole game?
Yes ... even though it might oveflow (it is uint32) which would potentially cause two or more entities to have same unit number, but I have never seen it even come close to overflowing.
Re: [0.15.16] luadoc for LuaEntity.unit_number
Posted: Tue May 30, 2017 4:10 pm
by folk
That's what I assumed

Thank you!
Oh, I see the thread was moved to "modding help". I opened it as a bug report specifically because I wanted the luadocs clarified in the name of posterity, future reference, and the good of mankind. I already assumed it behaved like you described it, but of course it's good to get it confirmed.
Re: [0.15.16] luadoc for LuaEntity.unit_number
Posted: Tue May 30, 2017 6:45 pm
by posila
I changed the doc as I moved the thread, but I felt like it is more appropriate to move the thread to Modding help rather than to resolved issues

Re: [0.15.16] luadoc for LuaEntity.unit_number
Posted: Tue May 30, 2017 7:50 pm
by Choumiko
posila wrote:Yes ... even though it might oveflow (it is uint32) which would potentially cause two or more entities to have same unit number, but I have never seen it even come close to overflowing.
Challenge accepted! Anyone?
I guess the same is true for LuaTrain:id
Re: [0.15.16] luadoc for LuaEntity.unit_number
Posted: Wed May 31, 2017 4:00 am
by Rseding91
Choumiko wrote:posila wrote:Yes ... even though it might oveflow (it is uint32) which would potentially cause two or more entities to have same unit number, but I have never seen it even come close to overflowing.
Challenge accepted! Anyone?
I guess the same is true for LuaTrain:id
Same for map tick as well
If you ever manage to overflow it in a normal game that isn't purpose-created to do so then I'll give you a free steam key because I don't think anyone will ever do it

Re: [0.15.16] luadoc for LuaEntity.unit_number
Posted: Wed May 31, 2017 8:03 am
by bobingabout
that's like, 2.3 years of game time before a tick overflow.
4 billion units is something that is far more obtainable. all you really need to do is set up a few biter farms, and eventually it will overflow.
what happens when it does overflow?
Re: [0.15.16] luadoc for LuaEntity.unit_number
Posted: Wed May 31, 2017 8:44 am
by Rseding91
bobingabout wrote:that's like, 2.3 years of game time before a tick overflow.
4 billion units is something that is far more obtainable. all you really need to do is set up a few biter farms, and eventually it will overflow.
what happens when it does overflow?
You'd have to kill > 1 per tick since the creation of the map for a total of 60 per second or 3600 biters per minute.
Re: [0.15.16] luadoc for LuaEntity.unit_number
Posted: Wed May 31, 2017 10:12 am
by bobingabout
Rseding91 wrote:bobingabout wrote:that's like, 2.3 years of game time before a tick overflow.
4 billion units is something that is far more obtainable. all you really need to do is set up a few biter farms, and eventually it will overflow.
what happens when it does overflow?
You'd have to kill > 1 per tick since the creation of the map for a total of 60 per second or 3600 biters per minute.
when I said 2.3 years, that's for the tick counter to overflow.
And yes, when you consider a map is infinite, if your goal is not to clear out nests, you can quite easily run a train line, protected by laser turrets, and have a result where biters are attacking constantly. do this in enough places and you can drastically reduce the amount of time before the unit counter over flows.
Re: [0.15.16] luadoc for LuaEntity.unit_number
Posted: Wed May 31, 2017 10:23 am
by Rseding91
bobingabout wrote:Rseding91 wrote:bobingabout wrote:that's like, 2.3 years of game time before a tick overflow.
4 billion units is something that is far more obtainable. all you really need to do is set up a few biter farms, and eventually it will overflow.
what happens when it does overflow?
You'd have to kill > 1 per tick since the creation of the map for a total of 60 per second or 3600 biters per minute.
when I said 2.3 years, that's for the tick counter to overflow.
And yes, when you consider a map is infinite, if your goal is not to clear out nests, you can quite easily run a train line, protected by laser turrets, and have a result where biters are attacking constantly. do this in enough places and you can drastically reduce the amount of time before the unit counter over flows.
You don't seem to understand

The map tick and unit number are both unsigned 32 bit numbers. The map tick advances at 1 per tick (obviously). The unit number only increments when a new entity using unit numbers is created. In order to cause a biter to be created you have to kill a biter which means in order to make the unit number advance faster than the map tick you would need to kill > 1 biter per game tick.
Re: [0.15.16] luadoc for LuaEntity.unit_number
Posted: Wed May 31, 2017 11:43 am
by bobingabout
ya, I get that. a good biter farm can easily be killing 10 biters a second.
if you find a large cluster of nests, and place laser turrets just outside the firing range to hit the nests, you'll have a steady stream of biters coming to attack the turrets and die.
I'll admit, the need to actually do this on purpose isn't really needed in the current game, but in a situation where the biters drop something you need, EG added by a mod, then this setup can become pretty standard.