Page 1 of 1

How to change other mod's research?

Posted: Wed Aug 10, 2022 11:49 pm
by Sesame_Slayer
I have been developing a mod to modify bob's adjustable inserters mod to make the tier two technologies go after Logistics 2 instead of Logistics 3, as it is more useful then. This is my first time using the Lua language. I made it dependent on bob's inserters to have my code override it, made the data and info files, and made a file where I copied the bob's inserters technology file's tier 2 research, and changed them to only red and green science, and have Logistics 2 instead of 3 as a prerequisite. However, in game, it doesn't do anything. Here's all my (janky) code:


Data:

Code: Select all

require("prototypes.technology")

Info:

Code: Select all

{
  "name": "BobInserters-Early-T2-Research",
  "version": "0.1.3",
  "title": "Bob Inserters Earlier T2 Research",
  "author": "Sesame_Slayer",
  "factorio_version": "1.1",
  "dependencies": ["base >= 1.1", "bobinserters >= 1.1.5"],
  "description": "Makes the long inserters and more inserters tier 2 researches from Bob's Adjustable Inserters line up with Logistics 2 instead of logistics 3, as at logistics 3 it is no longer needed. Report bugs on the mod portal."
}

My technology code:

Code: Select all

if settings.startup["bobmods-inserters-long2"].value == true and not data.raw.technology["long-inserters-2"] then
data:extend(
{
  {
    type = "technology",
    name = "long-inserters-2",
    icon = "__bobinserters__/graphics/icons/technology/long-inserters.png",
    icon_size = 128,
    effects =
    {
    },
    prerequisites =
    {
      "long-inserters-1",
      "logistics-2",
    },
    unit =
    {
      count = 50,
      ingredients =
      {
        {"automation-science-pack", 1},
        {"logistic-science-pack", 1},
      },
      time = 10
    },
    order = "a-f-a-2",
  },
}
)
end


if settings.startup["bobmods-inserters-more2"].value == true and not data.raw.technology["more-inserters-2"] then
data:extend(
{
  {
    type = "technology",
    name = "more-inserters-2",
    icon = "__bobinserters__/graphics/icons/technology/more-inserters.png",
    icon_size = 128,
    effects =
    {
    },
    prerequisites =
    {
      "more-inserters-1",
      "logistics-2",
    },
    unit =
    {
      count = 50,
      ingredients =
      {
        {"automation-science-pack", 1},
        {"logistic-science-pack", 1},
      },
      time = 10
    },
    order = "a-f-c-2",
  },
}
)
end
the file tree:
zip file
|main file
||prototypes
|||technology
||changelog
||data
||info
||thumbnail

How could I change it to work? am I missing something? I didn't really understand the mod tutorial page on the wiki. I saw something about a control document, but I don't understand it.

the mod portal link:
https://mods.factorio.com/mod/BobInsert ... 2-Research

Source code:
https://github.com/SesameSlayer/Bob-Ins ... ource-code

Re: How to change other mod's research?

Posted: Thu Aug 11, 2022 5:50 am
by Koub
[Koub] Moved to modding help

Re: How to change other mod's research?

Posted: Fri Aug 12, 2022 1:53 am
by Silari
If you just want to change the prerequisite why are you trying to redefine the entire technology? On top of that, your code is set up to not do anything at all if the technology already exists, except it's always going to exist because they're in bob's inserters, which your mod requires. I'm guessing you just copied the code wholesale out of the mod, which isn't going to work.

It's far easier to just test if the tech exists, and if it does change the prereqs. This should be all you need in data.lua:

Code: Select all

if data.raw.technology["long-inserters-2"] then
    data.raw.technology["long-inserters-2"].prerequisites =
    {
      "long-inserters-1",
      "logistics-2",
    }
end
if data.raw.technology["more-inserters-2"] then
    data.raw.technology["more-inserters-2"].prerequisites =
    {
      "more-inserters-1",
      "logistics-2",
    }
end
Can't test it, but that should do the job.

Re: How to change other mod's research?

Posted: Fri Aug 12, 2022 4:20 pm
by Sesame_Slayer
thanks! sorry, i've never made a mod before, so i just assumed redefining the technology would overwrite the old one.

Re: How to change other mod's research?

Posted: Fri Aug 12, 2022 4:44 pm
by Sesame_Slayer
Just realized, I also need to change science packs, because production and chemical science packs are after logistics 2. can i just add after data.raw.technology["long-inserters-2"].prerequisites, data.raw.technology["long-inserters-2"].ingredients and add the ingredients?

edit: didn't work, but your code did.

code is:

Code: Select all

if data.raw.technology["long-inserters-2"] then
    data.raw.technology["long-inserters-2"].prerequisites =
    {
      "long-inserters-1",
      "logistics-2",
    }
    data.raw.technology["long-inserters-2"].ingredients =
    {
        {"automation-science-pack", 1},
        {"logistic-science-pack", 1}
    }
end
if data.raw.technology["more-inserters-2"] then
    data.raw.technology["more-inserters-2"].prerequisites =
    {
      "more-inserters-1",
      "logistics-2",
    }
    data.raw.technology["more-inserters-2"].ingredients =
    {
        {"automation-science-pack", 1},
        {"logistic-science-pack", 1}
    }
end
Do I have to make it:

Code: Select all

data.raw.technology["long-inserters-2"].unit =
    {
      count = 50,
      ingredients =
      {
        {"automation-science-pack", 1},
        {"logistic-science-pack", 1},
      },
      time = 15
    },
    order = "a-f-a-2",
  },
}
end

Re: How to change other mod's research?

Posted: Fri Aug 12, 2022 5:02 pm
by DaveMcW
There is no ingredients property on the technology prototype.

You need data.raw.technology["long-inserters-2"].unit.ingredients

Re: How to change other mod's research?

Posted: Fri Aug 12, 2022 5:05 pm
by Sesame_Slayer
thanks! My mod finally works. I'll credit you in the changelog.