How to create entity with unit_number

Place to get help with not working mods / modding interface.
Post Reply
User avatar
IngoKnieto
Fast Inserter
Fast Inserter
Posts: 106
Joined: Mon Oct 03, 2016 9:29 am
Contact:

How to create entity with unit_number

Post 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?

Bilka
Factorio Staff
Factorio Staff
Posts: 3128
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: How to create entity with unit_number

Post 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?
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

User avatar
IngoKnieto
Fast Inserter
Fast Inserter
Posts: 106
Joined: Mon Oct 03, 2016 9:29 am
Contact:

Re: How to create entity with unit_number

Post 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
error.png (157.2 KiB) Viewed 1449 times

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5150
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: How to create entity with unit_number

Post by Klonan »

Not all entities have unit_number,

Try using `simple-entity-with-owner`

User avatar
IngoKnieto
Fast Inserter
Fast Inserter
Posts: 106
Joined: Mon Oct 03, 2016 9:29 am
Contact:

Re: How to create entity with unit_number [solved]

Post by IngoKnieto »

Thanks!

simple-entity-with-owner and simple-entity-with-force seem to have a unit number.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: How to create entity with unit_number

Post 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".
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.

Post Reply

Return to “Modding help”