Why is my command getting overwritten?

Place to get help with not working mods / modding interface.
iamdanthemanstan
Burner Inserter
Burner Inserter
Posts: 5
Joined: Wed Aug 11, 2021 7:26 pm
Contact:

Why is my command getting overwritten?

Post by iamdanthemanstan »

I'm very new to this and I was messing around with disabling hand mining. This line below worked fine:

Code: Select all

data.raw.character.mining_categories = nil
I was then messing around with adding new ores. I used some code from the Ice Ore mod to add one and it worked fine:

Code: Select all

local mod_name = "__test__"
local resource_autoplace = require("resource-autoplace")

-- Initialize the core patch sets in a predictable order
resource_autoplace.initialize_patch_set("ice-ore", true)



local name = "ice-ore"
local order = "a"


local autoplace_parameters = {
      base_density = 8,
      regular_rq_factor_multiplier = 1.0,
      starting_rq_factor_multiplier = 1.1
    }

local ice_ore = {
    type = "resource",
    name = "ice-ore",
    icon = mod_name.."/graphics/icons/" .. name .. ".png",
    icon_size = 32,
    flags = {"placeable-neutral"},
    order="a-b-"..order,
    tree_removal_probability = 0.8,
    tree_removal_max_distance = 32 * 32,
    minable =
    {
      -- mining_particle = name .. "-particle",
      mining_time = 1,
      result = name
    },
    collision_box = {{ -0.1, -0.1}, {0.1, 0.1}},
    selection_box = {{ -0.5, -0.5}, {0.5, 0.5}},
    autoplace = resource_autoplace.resource_autoplace_settings{
      name = name,
      order = order,
      base_density = 8,
      has_starting_area_placement = true,
      regular_rq_factor_multiplier = 1,
      starting_rq_factor_multiplier = 1.1,
      -- candidate_spot_count = autoplace_parameters.candidate_spot_count, -- idk, why 22 for iron ore and copper ore?
    },
    stage_counts = {16000, 8000, 2400, 1200, 640, 320, 160, 80},
    stages =
    {
      sheet =
      {
        filename = mod_name.."/graphics/entity/" .. name .. ".png",
        priority = "extra-high",
        width = 64,
        height = 64,
        frame_count = 8,
        variation_count = 8,
        hr_version =
          {
          filename = mod_name.."/graphics/entity/" .. "hr-" .. name .. ".png",
          priority = "extra-high",
          width = 128,
          height = 128,
          frame_count = 8,
          variation_count = 8,
          scale = 0.5
          }
      }
    },
    map_color = {r=0.85, g=0.85, b=1}
  }

data:extend(
{
  {
    type = "item",
    name = "ice-ore",
    icon = mod_name.."/graphics/icons/ice-ore.png",
    icon_size = 32,
    -- flags = {"goes-to-main-inventory"},
    subgroup = "raw-resource",
    order = "h",
    stack_size = 100
  },
}
)

data:extend(
{
  ice_ore,
  {
    type = "autoplace-control",
    name = name,
    richness = true,
    order = "i-o-"..order,
    category = "resource"
  },
  {
    type = "noise-layer",
    name = name
  }
}
)
However now hand mining is enabled again. I don't see why anything in this code from Ice Ore would make the other line not work. "data.raw.character.mining_categories = nil" doesn't work no matter if it goes before or after the Ice Ore code. What am I not understanding about how these interact?
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3749
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Why is my command getting overwritten?

Post by DaveMcW »

Code: Select all

data.raw["character"]["character"].mining_categories = nil
I always use the bracket notation when editing data.raw, it is a helpful reminder to include the type and name.
iamdanthemanstan
Burner Inserter
Burner Inserter
Posts: 5
Joined: Wed Aug 11, 2021 7:26 pm
Contact:

Re: Why is my command getting overwritten?

Post by iamdanthemanstan »

DaveMcW wrote: Thu Aug 12, 2021 11:18 pm

Code: Select all

data.raw["character"]["character"].mining_categories = nil
I always use the bracket notation when editing data.raw, it is a helpful reminder to include the type and name.
Thank you that worked. But why did it work? "data.raw.character.mining_categories = nil" was working before I added the code from Ice Ore. Also, is it an aspect of Factorio or Lua that uses the [][] notation for referring to something? What sort of a data structure does data.raw have anyways?
Post Reply

Return to “Modding help”