[0.17.68] LuaItemStack.set_blueprint_entity_tag() doesn't set tag

Bugs that are actually features.
Post Reply
mrvn
Smart Inserter
Smart Inserter
Posts: 5699
Joined: Mon Sep 05, 2016 9:10 am
Contact:

[0.17.68] LuaItemStack.set_blueprint_entity_tag() doesn't set tag

Post by mrvn »

I'm trying to set a tag in a blueprint but right after setting the tag reading it back results in nil.

control.lua:

Code: Select all

local function player_setup_blueprint(event)
  log("player_setup_blueprint")
  local player = game.players[event.player_index]
  local bp = player.blueprint_to_setup
  if not bp or not bp.valid_for_read then
    bp = player.cursor_stack
  end
  if not bp or not bp.valid_for_read then
    return
  end
  local entities = bp.get_blueprint_entities()
  if not entities then
    return
  end
  for i, entity in ipairs(entities) do
    if entity.name == "tag-chest" then
      log("adding tag to tag-chest")
      bp.set_blueprint_entity_tag(i, "example-tag", entity.unit_number)
      log("example-tag = " .. serpent.block(bp.get_blueprint_entity_tag(i, "example-tag")))
    end
  end
end
data.lua:

Code: Select all

local tag_chest = table.deepcopy(data.raw["container"]["wooden-chest"])
tag_chest.name = "tag-chest"
tag_chest.minable = {mining_time = 1, result = "tag-chest"}

data:extend {
  {
    type = "item-with-tags",
    name = "tag-chest",
    icon = "__base__/graphics/icons/wooden-chest.png",
    icon_size = 32,
    flags = {},
    subgroup = "other",
    order = "s[item-with-tags]-o[item-with-tags]",
    stack_size = 1,
    place_result = "tag-chest",
  },
  tag_chest,
  {
    type = "recipe",
    name = "tag-chest",
    ingredients = {},
    result = "tag-chest"
  },
}
Attachments
LogisticTrainOrganizer_0.0.0.zip
(14.82 KiB) Downloaded 37 times

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

Re: [0.17.68] LuaItemStack.set_blueprint_entity_tag() doesn't set tag

Post by Klonan »

entity.unit_number is nil, so you are setting the tag to nil

mrvn
Smart Inserter
Smart Inserter
Posts: 5699
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: [0.17.68] LuaItemStack.set_blueprint_entity_tag() doesn't set tag

Post by mrvn »

Klonan wrote:
Tue Sep 10, 2019 1:17 pm
entity.unit_number is nil, so you are setting the tag to nil
That's bad. Then how do I get the actual entity that is being blueprinted to take data from?

This could be merged with viewtopic.php?f=28&t=75369 as it's the same issue.

Post Reply

Return to “Not a bug”