My code for building blueprints from string not working

Place to get help with not working mods / modding interface.
Post Reply
MartinMaxKing
Burner Inserter
Burner Inserter
Posts: 9
Joined: Sun Oct 09, 2022 12:47 pm
Contact:

My code for building blueprints from string not working

Post by MartinMaxKing »

Code: Select all

local bp_string = "your blueprint string here"
local surface = game.player.surface
local bp_entity = surface.create_entity{name = 'item-on-ground', position= game.player.position, stack = 'blueprint'}

bp_entity.stack.import_stack(bp_string)
local bp_entities = bp_entity.stack.get_blueprint_entities(bp_string)
local bpInfo = {surface = surface, force = "north", position= game.player.position, force_build = 'true', direction = 0, skip_fog_of_war = 'true', by_player = player, raise_built = 'false'}
local bpResult = bp_entity.stack.build_blueprint(bpInfo)
bp_entity.destroy()
I'm testing this code I got on BB server. Want to use it for building entities from blueprints string for faster game setups but it's not building.

It is placing blueprint ghosts but the second part of the code is not building those entities. I don't know why.

PFQNiet
Filter Inserter
Filter Inserter
Posts: 289
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: My code for building blueprints from string not working

Post by PFQNiet »

The "second part of the code" is what is placing the ghosts. None of the code you have posted calls "revive" on the ghosts to make them real.

User avatar
Silari
Filter Inserter
Filter Inserter
Posts: 490
Joined: Sat Jan 27, 2018 10:04 pm
Contact:

Re: My code for building blueprints from string not working

Post by Silari »

This code grabs the value 'bp_entities' and then does nothing with it, while providing a parameter when the function doesn't take any. It's entirely superflous - maybe it was used for debugging at one point, but it really doesn't need to be there.

Biggest issue is it keeps a copy of the return from build_blueprint and does nothing with it. The array it returns is what lists all the ghost entities it makes - iterating that array and calling the revive method is how you'd actually build the entities for the placed ghosts.

MartinMaxKing
Burner Inserter
Burner Inserter
Posts: 9
Joined: Sun Oct 09, 2022 12:47 pm
Contact:

Re: My code for building blueprints from string not working

Post by MartinMaxKing »

Thank You guys. Now I understand :)

Post Reply

Return to “Modding help”