Page 1 of 1
[Solved]Hide a recipe/item from inside technology
Posted: Wed Oct 18, 2023 9:25 am
by dtoxic
So i wanted to change the steam engine from unlocking in one technology and unlock in another witch i managed to do like this
Code: Select all
table.insert(data.raw["technology"]["steam-power"].effects,{type = "unlock-recipe",recipe = "steam-engine"})
But now i have two recipes inside the "steam-power" and from another mod technology "electric-machinery" i would like to hide the recipe for the steam engine from "electric-machinery" technology
is there a Wizard who could point me on an adventure of coding land,and what is to be done so i can complete this quest?
Re: Hide a recipe/item from inside technology
Posted: Wed Oct 18, 2023 11:12 am
by FuryoftheStars
It's gonna be hours before I can open up my own mod code to refresh my memory on this, but if you take a look at the code in my
Classic Factorio Basic Oil Processing mod, I move a bunch of recipes around in the techs, so there are examples of inserting and removing in there. The code shouldn't be overly complex, either, as it's just moving recipes and changing a few recipes based on settings. Nothing truly new or complex.
Re: Hide a recipe/item from inside technology
Posted: Wed Oct 18, 2023 11:14 am
by dtoxic
Will check that out now,thank you kindly
Re: Hide a recipe/item from inside technology
Posted: Wed Oct 18, 2023 11:38 am
by dtoxic
Nope,cant make a sense of the code,all i see changing the prerequisite for technologies and adding/removing? ingredients...but thank you anyway,will wait for some other explanation
Re: Hide a recipe/item from inside technology
Posted: Wed Oct 18, 2023 12:43 pm
by Pi-C
dtoxic wrote: ↑Wed Oct 18, 2023 9:25 am
So i wanted to change the steam engine from unlocking in one technology and unlock in another witch i managed to do like this
Code: Select all
table.insert(data.raw["technology"]["steam-power"].effects,{type = "unlock-recipe",recipe = "steam-engine"})
But now i have two recipes inside the "steam-power" and from another mod technology "electric-machinery" i would like to hide the recipe for the steam engine from "electric-machinery" technology
Code: Select all
local tech = data.raw.technology["electric-machinery"]
if tech and tech.effects then
local new_effects = {}
for e, effect in pairs(tech.effects) do
if not (effect.type == "unlock-recipe" and effect.recipe == "steam-engine") then
table.insert(new_effects, effect)
end
end
tech.effects = next(new_effects) and table.deepcopy(new_effects) or nil
end
Technology effects are optional, so this will only run if the technology exists and has effects. Even if technology.effects does exist, you don't know what other mods may have changed before yours, so there is a chance that tech.effects contains the same unlock recipe more than once. Therefore, we go over all effects and copy every effect that is not an unlock-recipe for the steam-engine to the table new_effects. When that is done, we use next(new_effects) to check whether the table contains any elements. If it does, we overwrite tech.effects with new_effects; if it's empty, we remove tech.effects by setting it to nil.
Does that help, or did I miss something?
Re: Hide a recipe/item from inside technology
Posted: Wed Oct 18, 2023 1:35 pm
by dtoxic
Just one question will this now also remove the "steam-engine" from technology "steam-power" witch i added with my code?
Re: Hide a recipe/item from inside technology
Posted: Wed Oct 18, 2023 1:40 pm
by Pi-C
No. As tech has been defined as
Code: Select all
local tech = data.raw.technology["electric-machinery"]
the "steam-engine" recipe will be removed only from the effects of "electric-machinery".
Re: Hide a recipe/item from inside technology
Posted: Wed Oct 18, 2023 1:41 pm
by dtoxic
ahh great...every day one learns more,thank you
Re: [Solved]Hide a recipe/item from inside technology
Posted: Wed Oct 18, 2023 2:16 pm
by Pi-C
You're welcome, glad I could help!
Re: [Solved]Hide a recipe/item from inside technology
Posted: Wed Oct 18, 2023 2:31 pm
by dtoxic
btw,i put it data-final-fixes to make it work because in data-updates it would not stick...
Re: [Solved]Hide a recipe/item from inside technology
Posted: Wed Oct 18, 2023 4:31 pm
by Pi-C
Looks like some other mod changed it after your mod was done in data-updates.lua. Hover over the "electric-machinery" tech in the tech tree, and you'll see the mods that have modified the tech. If you'd find the mod that adds the unlock, you could add a dependency on it to force it to load before your mod. This way, you could keep your changes in data-updates.lua.
Re: [Solved]Hide a recipe/item from inside technology
Posted: Wed Oct 18, 2023 5:40 pm
by dtoxic
Thx will check it out
Re: Hide a recipe/item from inside technology
Posted: Wed Oct 18, 2023 10:57 pm
by FuryoftheStars
dtoxic wrote: ↑Wed Oct 18, 2023 11:38 am
Nope,cant make a sense of the code,all i see changing the prerequisite for technologies and adding/removing? ingredients...but thank you anyway,will wait for some other explanation
Ah, sorry about that. I could've sworn I did some recipe moving in there too, but maybe not. It has been a while since I've needed to look at that mod's code.
Glad Pi-C was able to help you out and you got your problem solved, though.
Re: [Solved]Hide a recipe/item from inside technology
Posted: Thu Oct 19, 2023 7:47 am
by dtoxic
No problem,also my coding skills are not that good but thanks for trying