Page 1 of 1
How can I edit every instance of a prototype type?
Posted: Wed Aug 11, 2021 7:47 pm
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.
Re: How can I edit every instance of a prototype type?
Posted: Wed Aug 11, 2021 7:51 pm
by Klonan
Yes
Code: Select all
for name, prototype in pairs (data.raw["technology"]) do
prototype.enabled = false
end
Re: How can I edit every instance of a prototype type?
Posted: Wed Aug 11, 2021 8:37 pm
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.
Re: How can I edit every instance of a prototype type?
Posted: Wed Aug 11, 2021 9:27 pm
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".
Re: How can I edit every instance of a prototype type?
Posted: Wed Aug 11, 2021 9:47 pm
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
Re: How can I edit every instance of a prototype type?
Posted: Wed Aug 11, 2021 11:06 pm
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