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?
How to create entity with unit_number
- IngoKnieto
- Fast Inserter
- Posts: 106
- Joined: Mon Oct 03, 2016 9:29 am
- Contact:
Re: How to create entity with 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.IngoKnieto wrote:How can I create an entity by script with a unit_number?
What type of entity are you creating? Does it support unit_number?
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
- IngoKnieto
- Fast Inserter
- Posts: 106
- Joined: Mon Oct 03, 2016 9:29 am
- Contact:
Re: How to create entity with unit_number
The type is "simple-entity".
This is how it is created (shortened):
This is the error thrown by the print line:
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)
Re: How to create entity with unit_number
Not all entities have unit_number,
Try using `simple-entity-with-owner`
Try using `simple-entity-with-owner`
- IngoKnieto
- Fast Inserter
- Posts: 106
- Joined: Mon Oct 03, 2016 9:29 am
- Contact:
Re: How to create entity with unit_number [solved]
Thanks!
simple-entity-with-owner and simple-entity-with-force seem to have a unit number.
simple-entity-with-owner and simple-entity-with-force seem to have a unit number.
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: How to create entity with unit_number
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".
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.