Determining the main_product of a recipe

Place to get help with not working mods / modding interface.
Post Reply
Pi-C
Smart Inserter
Smart Inserter
Posts: 1045
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Determining the main_product of a recipe

Post by Pi-C »

Suppose there is a recipe with >2 results. It doesn't have recipe.subgroup, so recipe.main_product is requiresd. (To keep this simple, let's ignore difficulties -- I know they can exist, but they are not relevant to my question.)

Replacing a result x for result y is easy:

Code: Select all

if recipe.results["x"].name == recipe.main_product then 
	recipe.main_product = recipe.results["y"].name 
end
But what if I remove result x and this was the main_product? Setting a new main_product is easy when I work on a single recipe -- but not if I want to loop over all available recipes. Sure, I could use the first result, or the one with the highest amount, or the only one without probability, but all of that seems to be only half-baked. Did anybody else already think about this?
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Post Reply

Return to “Modding help”