Page 1 of 1

[0.12.10] Circuit network get_blueprint_entities and create_entity

Posted: Sun Oct 04, 2015 2:36 pm
by RepairMan
Steps to reproduce:
1. Connect 2 constant combinators like in the image below
Image
2. Place a blueprint of them in the first slot of your quicker
3. Execute the follow code in the console. It's gonna place the entity of the blueprint using the create_entity methode

Code: Select all

/c local es = game.player.character.get_inventory(defines.inventory.player_quickbar)[1].get_blueprint_entities() for k,v in pairs (es) do local g={} for k,v in pairs(v) do g[k]=v end g.inner_name=v.name g.inner_name=v.name g.position.x=g.position.x+game.player.position.x g.position.y=g.position.y+game.player.position.y g.force=game.player.force game.surfaces.nauvis.create_entity(g) end


Expected results: The 2 constant combinators connected by a red wire shut be placed at the players position

Actual results: The 2 constant combinators get placed without red wire connecting them

Re: [0.12.10] Circuit network get_blueprint_entities and create_entity

Posted: Sun Oct 04, 2015 2:40 pm
by Zeblote
It doesn't even make sense to connect them like this, does it?

Re: [0.12.10] Circuit network get_blueprint_entities and create_entity

Posted: Sun Oct 04, 2015 2:49 pm
by RepairMan
Zeblote wrote:It doesn't even make sense to connect them like this, does it?
It's an example, if you want just connect a constant combinator and a lamp or something else, the result shall be the same.

Re: [0.12.10] Circuit network get_blueprint_entities and create_entity

Posted: Sun Oct 04, 2015 3:49 pm
by gheift
In the blueprint the connections are stored with an index, which is unique inside this blueprint, but not in the game. You copy the properties of the placed entities with

Code: Select all

local g={} for k,v in pairs(v) do g[k]=v end
and places them one by one.

The connection of the entites are stored for example as follow:

Code: Select all

  [1] = { name = "constant-combinator", connection = { "red" = 2, "green" = 3 } },
  [2] = { name = "constant-combinator", connection = { "red" = 1 } },
  [3] = { name = "constant-combinator", connection = { "green" = 1 } },
(This is not the actual format, only to demonstarte…)

When the entity is createrd with

Code: Select all

game.surfaces.nauvis.create_entity(g)
then game does not know, what entity 1, 2 or 3 is. A workaround would be to process the blueprint by yourself and call

Code: Select all

connect_neighbour
appropriatly. A better solution would be an exposed api function like

Code: Select all

game.surface.nauvis.place_blueprint(…)
https://forums.factorio.com/wiki/inde ... _neighbour

Re: [0.12.10] Circuit network get_blueprint_entities and create_entity

Posted: Sun Oct 04, 2015 3:57 pm
by Adil
create_entity is a simple function for spawning arbitrary entity, it is not supposed to copy your blueprints.
You'd need to manually obtain from blueprint and handle the additional properties like connections and filters.
Also, if you're planning on using that as a normal method of building, don't forget to raise on_entity_build event for each entity created, otherwise more than a number of mods will break down.

Re: [0.12.10] Circuit network get_blueprint_entities and create_entity

Posted: Sun Oct 04, 2015 4:38 pm
by RepairMan
Sorry for the trouble,
@gheift Could you help me with that?

Re: [0.12.10] Circuit network get_blueprint_entities and create_entity

Posted: Sun Oct 04, 2015 5:16 pm
by kovarex
Well, this is definitely not a bug. Script interface to build blueprint at certain location would make sense though.