Event for when expensive recipes are selected?
Event for when expensive recipes are selected?
So my Recycling Machines Mod https://mods.factorio.com/mods/DRY411S/ZRecycling works by loading all the vanilla and installed mods recipes and reverses them by turning the original results into ingredients and the original ingredients into results.
It does this in the game data stage when the game is initially started by players.It has to use the data stage because the recipes form part of data.raw.
The problem is that at that stage there are normal ingredients and expensive ingredients, and I have to choose one or the other as the results of the recycling recipes. I'm defaulting to the normal ingredients at the moment.
Is there an event I can trap in control.lua that would allow me to alter the ingredients in data.raw when people start a new map, and decide to use expensive ingredients?
It does this in the game data stage when the game is initially started by players.It has to use the data stage because the recipes form part of data.raw.
The problem is that at that stage there are normal ingredients and expensive ingredients, and I have to choose one or the other as the results of the recycling recipes. I'm defaulting to the normal ingredients at the moment.
Is there an event I can trap in control.lua that would allow me to alter the ingredients in data.raw when people start a new map, and decide to use expensive ingredients?
Re: Event for when expensive recipes are selected?
Why not just define both a normal and expensive recipe?DRY411S wrote:So my Recycling Machines Mod https://mods.factorio.com/mods/DRY411S/ZRecycling works by loading all the vanilla and installed mods recipes and reverses them by turning the original results into ingredients and the original ingredients into results.
It does this in the game data stage when the game is initially started by players.It has to use the data stage because the recipes form part of data.raw.
The problem is that at that stage there are normal ingredients and expensive ingredients, and I have to choose one or the other as the results of the recycling recipes. I'm defaulting to the normal ingredients at the moment.
Is there an event I can trap in control.lua that would allow me to alter the ingredients in data.raw when people start a new map, and decide to use expensive ingredients?
Re: Event for when expensive recipes are selected?
Normal and expensive reverse recipes?Klonan wrote:Why not just define both a normal and expensive recipe?
Re: Event for when expensive recipes are selected?
SureDRY411S wrote:Normal and expensive reverse recipes?Klonan wrote:Why not just define both a normal and expensive recipe?
Re: Event for when expensive recipes are selected?
So is there a variable I can test to see whether the player is using expensive recipes?Klonan wrote:SureDRY411S wrote:Normal and expensive reverse recipes?Klonan wrote:Why not just define both a normal and expensive recipe?
Re: Event for when expensive recipes are selected?
I think you are not realizing something.DRY411S wrote:So is there a variable I can test to see whether the player is using expensive recipes?Klonan wrote:SureDRY411S wrote:Normal and expensive reverse recipes?Klonan wrote:Why not just define both a normal and expensive recipe?
Take a look at base game data - some recipes (like electronics) have two sections in recipe - normal and expensive.
So your reversed recipe needs to be done in same way. You need to reverse normal section into your normal section and same with expensive section. Then game will select correct one based on the setting.
Like this one:
Code: Select all
{
type = "recipe",
name = "electronic-circuit",
normal =
{
ingredients =
{
{"iron-plate", 1},
{"copper-cable", 3}
},
result = "electronic-circuit",
requester_paste_multiplier = 50
},
expensive =
{
ingredients =
{
{"iron-plate", 2},
{"copper-cable", 10}
},
result = "electronic-circuit",
requester_paste_multiplier = 50
},
},
Re: Event for when expensive recipes are selected?
Thanks that works if I can have an array of results instead of a singular result. I'll give it a try.
- Ranakastrasz
- Smart Inserter
- Posts: 2179
- Joined: Thu Jun 12, 2014 3:05 am
- Contact:
Re: Event for when expensive recipes are selected?
I think you can put the result in the easy/hard crafting suitable. At least I hope so.DRY411S wrote:Thanks that works if I can have an array of results instead of a singular result. I'll give it a try.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
- bobingabout
- Smart Inserter
- Posts: 7352
- Joined: Fri May 09, 2014 1:01 pm
- Contact:
Re: Event for when expensive recipes are selected?
I don't even understand what the issue is.
if normal exists, then expensive exists too.
do a check to see if these tags exist, if they don't, business as usual.
if they do, simply do what you normally do, except you do the recipe reversing part twice, inside both normal, and expensive. I mean, Both the ingredients and result/results tags exist inside normal/expensive, just the same as outside of them.
it literally is that simple.
if normal exists, then expensive exists too.
do a check to see if these tags exist, if they don't, business as usual.
if they do, simply do what you normally do, except you do the recipe reversing part twice, inside both normal, and expensive. I mean, Both the ingredients and result/results tags exist inside normal/expensive, just the same as outside of them.
it literally is that simple.
Re: Event for when expensive recipes are selected?
You (and the others above) are right. There isn't an issue, I was having a brain meltdown, thinking that my reverse recipes must be either normal or expensive, when in fact they can be both.bobingabout wrote:I don't even understand what the issue is.
Thanks for steering me on the right course folks.
- bobingabout
- Smart Inserter
- Posts: 7352
- Joined: Fri May 09, 2014 1:01 pm
- Contact:
Re: Event for when expensive recipes are selected?
I'm glad that you've figured it out then 

-
- Long Handed Inserter
- Posts: 88
- Joined: Fri Apr 22, 2016 9:55 pm
- Contact:
Re: Event for when expensive recipes are selected?
A word of warning, this is apparently not strictly true. I recently had a request to change some of my code to make it compatible with a mod that was creating recipes with expensive but not normal variants. As a result, I had to move to something like this:bobingabout wrote:if normal exists, then expensive exists too.
Code: Select all
if recipe.normal or recipe.expensive then
if recipe.normal then
--do stuff with normal version
end
if recipe.expensive then
--do stuff with expensive version
end
else
--do stuff with base version
end
Re: Event for when expensive recipes are selected?
Your username is ace in these circumstances.Exasperation wrote:A word of warning, this is apparently not strictly true. I recently had a request to change some of my code to make it compatible with a mod that was creating recipes with expensive but not normal variants. As a result, I had to move to something like this:bobingabout wrote:if normal exists, then expensive exists too.Code: Select all
if recipe.normal or recipe.expensive then if recipe.normal then --do stuff with normal version end if recipe.expensive then --do stuff with expensive version end else --do stuff with base version end

So the mod that had expensive recipes only? What happened when people generated maps with normal recipes? Which mod was it?
(If the mod has only expensive recipes, I'd have pushed back on the mod developer and requested that they had just recipe.ingredients ~= nil instead)
I have inspected all vanilla recipes now, and they have recipe.ingredients ~= nil OR (recipe.normal.ingredients ~= nil AND recipe.expensive.ingredients ~= nil)
I've released a new version of my mod where the code assumes this.
-
- Long Handed Inserter
- Posts: 88
- Joined: Fri Apr 22, 2016 9:55 pm
- Contact:
Re: Event for when expensive recipes are selected?
I don't remember exactly which mod it was, but it was some marathon-style mod. Given that, I suppose "all my users are going to use expensive recipes" was a reasonable assumption on their part. I honestly didn't test to see what happened if a recipe only had an expensive version but the difficulty was set to normal (or vice versa), I just did one of these
, made the change to avoid my code crashing from attempting to index a nil, and let it be their problem to deal with from then on.
And yes, all of the vanilla recipes either have both normal + expensive or neither.

And yes, all of the vanilla recipes either have both normal + expensive or neither.
Re: Event for when expensive recipes are selected?
Well I guess if the mod writer had only one recipe, they should just ignore the normal and expensive constructs.Exasperation wrote:I don't remember exactly which mod it was, but it was some marathon-style mod. Given that, I suppose "all my users are going to use expensive recipes" was a reasonable assumption on their part. I honestly didn't test to see what happened if a recipe only had an expensive version but the difficulty was set to normal (or vice versa), I just did one of these, made the change to avoid my code crashing from attempting to index a nil, and let it be their problem to deal with from then on.
And yes, all of the vanilla recipes either have both normal + expensive or neither.