How would I make this code work with optional dependencies?

Place to get help with not working mods / modding interface.
Post Reply
Sesame_Slayer
Burner Inserter
Burner Inserter
Posts: 14
Joined: Wed Aug 10, 2022 10:12 pm
Contact:

How would I make this code work with optional dependencies?

Post by Sesame_Slayer »

I've gotten a suggestion to add Crux chests to a mod I have made that allows you to either put Logistic system's contents and prerequisites into Logistic robotics, or simply make it so that Logistic system is cheaper, these modes toggleable by a startup setting. The "make cheaper" part works fine, but I can't find a way to expand the first option. How would I go about this? currently, the code only deletes the Crux Chests techs, but does nothing to move the contents to Logistic robotics. Additionally, I've found an error with my old code, where it only moves the 3 logistics chests (I replaced the code for moving effects with table.insert(tech.effects, {type = "unlock-recipe", recipe = "logistic-chest-buffer"}), which is an example of the code I used to use (which was just it copied 3 times)). How could I fix both issues?
Data.lua:

Code: Select all

local my_setting = settings.startup["earlierlogisticsmainsetting"]
if my_setting and my_setting.value == "merge" then

  local tech = data.raw.technology["logistic-robotics"]

  if tech then
    tech.effects = tech.effects or {}

    table.insert(tech.effects, {type = "unlock-recipe", recipe = "logistic-chest-buffer"}) -- all lines like this should be changed to something that can move all effects of a technology.
  end

  tech = data.raw.technology["logistic-system"]
  if tech then
    tech.enabled = false
    tech.hidden = true
  end

  if mods["cruxchests"] then
    tech = data.raw.technology["cruxchests-tech2"]
    if tech then
      tech.enabled = false
      tech.hidden = true
    end

    tech = data.raw.technology["cruxchests-tech3"]
    if tech then
      tech.enabled = false
      tech.hidden = true
    end
  end
end

local my_setting = settings.startup["earlierlogisticsmainsetting"]
if my_setting and my_setting.value == "changepack" then

  tech = data.raw.technology["logistic-system"]

  if tech then
    tech.prerequisites =
    {
      "logistic-robotics",
      "chemical-science-pack",
    }
    tech.unit.count = 150
    tech.unit.ingredients =
    {
      {"automation-science-pack", 1},
      {"logistic-science-pack", 1},
      {"chemical-science-pack", 1}
    }
  end

  if mods["cruxchests"] then

    tech = data.raw.technology["cruxchests-tech3"]

    if tech then
      tech.unit.ingredients =
      {
        {"automation-science-pack", 1},
        {"logistic-science-pack", 1},
        {"chemical-science-pack", 1}
      }
    end
  end
end
Half the time, I'm half asleep.

Post Reply

Return to “Modding help”