Page 1 of 1
How to create entity with unit_number
Posted: Sun Sep 02, 2018 11:14 am
by IngoKnieto
As far as I know every entity build by the player has the unique property "unit_number". However if I place an entity by script using surface.create_entity the unit_number of that entity is nil.
How can I create an entity by script with a unit_number?
Re: How to create entity with unit_number
Posted: Sun Sep 02, 2018 11:26 am
by Bilka
IngoKnieto wrote:How can I create an entity by script with a unit_number?
You just create the entity normally. The simple test case of /c game.print(game.player.surface.create_entity{name = "transport-belt", position = game.player.position}.unit_number) prints the unit number and not nil.
What type of entity are you creating? Does it support unit_number?
Re: How to create entity with unit_number
Posted: Sun Sep 02, 2018 12:55 pm
by IngoKnieto
The type is "simple-entity".
This is how it is created (shortened):
Code: Select all
ruin = surface.create_entity{
name=REACTOR_RUIN_NAME,
position=dead_reactor_core.position,
force=dead_reactor_core.force,
}
[...]
game.players[1].print("ruin.unit_number "..ruin.unit_number)
This is the error thrown by the print line:

- error.png (157.2 KiB) Viewed 2078 times
Re: How to create entity with unit_number
Posted: Sun Sep 02, 2018 1:05 pm
by Klonan
Not all entities have unit_number,
Try using `simple-entity-with-owner`
Re: How to create entity with unit_number [solved]
Posted: Sun Sep 02, 2018 1:10 pm
by IngoKnieto
Thanks!
simple-entity-with-owner and simple-entity-with-force seem to have a unit number.
Re: How to create entity with unit_number
Posted: Mon Sep 03, 2018 10:58 am
by eradicator
Just because it might be relevant:
Rseding91 wrote:
Simple-entity-with-force is "will be targeted by biters/turrets",
Simple-entity-with-owner is "has a force, but is only attacked if the biters get stuck on it".