Page 1 of 1

My code for building blueprints from string not working

Posted: Sun Oct 23, 2022 4:39 pm
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.

Re: My code for building blueprints from string not working

Posted: Sun Oct 23, 2022 8:55 pm
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.

Re: My code for building blueprints from string not working

Posted: Mon Oct 24, 2022 1:32 am
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.

Re: My code for building blueprints from string not working

Posted: Mon Oct 24, 2022 5:07 pm
by MartinMaxKing
Thank You guys. Now I understand :)