How can I edit every instance of a prototype type?

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:

How can I edit every instance of a prototype type?

Post by iamdanthemanstan »

I want to disable all the technologies. This:

Code: Select all

data.raw["technology"]["advanced-electronics"].enabled = "false"
works for disabling one random tech but is there a way to do this for all of them without referencing each one specifically. I tried

Code: Select all

data.raw["technology"][].enabled = "false"
and

Code: Select all

data.raw["technology"].enabled = "false"
but both just gave errors. So can I effect every tech at the same time? Alternatively, are the names all stored in a list somewhere so I could pull them and run a loop? Thanks.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5409
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: How can I edit every instance of a prototype type?

Post by Klonan »

iamdanthemanstan wrote: Wed Aug 11, 2021 7:47 pm run a loop?
Yes

Code: Select all

for name, prototype in pairs (data.raw["technology"]) do
  prototype.enabled = false
end
iamdanthemanstan
Burner Inserter
Burner Inserter
Posts: 5
Joined: Wed Aug 11, 2021 7:26 pm
Contact:

Re: How can I edit every instance of a prototype type?

Post by iamdanthemanstan »

Thank you that's very helpful.

I am also trying to disable all recipes. I tried the code below and while it disabled a lot of the recipes it didn't work for all.

Code: Select all

for name, prototype in pairs (data.raw["recipe"]) do
  prototype.enabled = false
end
Looking through the prototype definitions it seems recipes have a category, but I'm not sure how to reference that. I tried the code below but got errors. How do I reference the part of data.raw for a specific category of recipe?

[code]for name, prototype in pairs (data.raw["recipe"]["crafting-with-fluidg"]) do
prototype.enabled = false
end[/code]


My initial thoughts weren't correct. I'm not sure why but pipes, iron gears, green circuits, steam engines, and both miners are not being disabled.
PFQNiet
Filter Inserter
Filter Inserter
Posts: 290
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: How can I edit every instance of a prototype type?

Post by PFQNiet »

Recipes are a hydra. You have to set enabled = false but also check if they have a "normal" and if so set normal.enabled = false, and again for "expensive".
iamdanthemanstan
Burner Inserter
Burner Inserter
Posts: 5
Joined: Wed Aug 11, 2021 7:26 pm
Contact:

Re: How can I edit every instance of a prototype type?

Post by iamdanthemanstan »

Big thanks. For anyone coming to this later here is the code that worked per PFQNiet's suggestion.

Code: Select all

for name, prototype in pairs (data.raw["recipe"]) do
  prototype.enabled = false
  if prototype["normal"] then 
    prototype.normal.enabled = false 
    prototype.expensive.enabled = false
  end
end
User avatar
Silari
Filter Inserter
Filter Inserter
Posts: 586
Joined: Sat Jan 27, 2018 10:04 pm
Contact:

Re: How can I edit every instance of a prototype type?

Post by Silari »

iamdanthemanstan wrote: Wed Aug 11, 2021 9:47 pm Big thanks. For anyone coming to this later here is the code that worked per PFQNiet's suggestion.

Code: Select all

for name, prototype in pairs (data.raw["recipe"]) do
  prototype.enabled = false
  if prototype["normal"] then 
    prototype.normal.enabled = false 
    prototype.expensive.enabled = false
  end
end
While I don't think it'll cause you trouble in vanilla, this has two issues. You should check if normal exists and if expensive exists separately, since you can specify one without the other, and it's also possible to set it equal to false to disable it for that difficulty. The first issue is that if normal is defined and expensive isn't, this code would create an error by trying to reference a property of the nil expensive value. The second is that if expensive is defined but normal isn't, your code won't disable the recipe properly.

Code: Select all

for name, prototype in pairs (data.raw["recipe"]) do
  prototype.enabled = false
  if prototype["normal"] then 
    prototype.normal.enabled = false 
  end
  if prototype["expensive"] then
    prototype.expensive.enabled = false
  end
end
should be enough to fix both those potential issues.

See https://wiki.factorio.com/Prototype/Recipe#normal for the details
Post Reply

Return to “Modding help”