Discussion about recipe result formats

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Discussion about recipe result formats

Post by eradicator »

Pi-C wrote:
Sun Apr 25, 2021 6:22 pm
https://wiki.factorio.com/Types/ItemProductPrototype wrote: amount_min and amount_max

Type: Types/uint16

Mandatory if amount is not specified and named keys are being used.
When using named keys, either amount or (amount_min and amount_max) must be set. But what happens if all are used?
You mean something like this? I think the general rule of thumb is that it always uses the most specific entry, but written clarification would clearly not hurt. Best in a form that tells the user not to attempt such mixtures in the first place.

Code: Select all

{'apple', 1, name='pear', amount=42, amount_min=7, amount_max=3}
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1651
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Small documentation improvement requests

Post by Pi-C »

eradicator wrote:
Sun Apr 25, 2021 9:18 pm
Pi-C wrote:
Sun Apr 25, 2021 6:22 pm
When using named keys, either amount or (amount_min and amount_max) must be set. But what happens if all are used?
You mean something like this? I think the general rule of thumb is that it always uses the most specific entry, but written clarification would clearly not hurt. Best in a form that tells the user not to attempt such mixtures in the first place.

Code: Select all

{'apple', 1, name='pear', amount=42, amount_min=7, amount_max=3}
Your case has already been covered at the top of the page:
An item product definition for a Prototype/Recipe. Its loading is triggered by the type of a Types/ProductPrototype being "item". It can be specified as a table with named or numbered keys, but not a mix of both.
I was particularly interested in the amount part. The description of amount_max already has:
"If set to a number that is less than amount_min, the game will use amount_min internally. "
But how about a simple case like

Code: Select all

{name='pear', amount=42, amount_min=3, amount_max=7}
I'd assume that "amount=42" would win in this case, but there's room for doubt -- it could also be the range amount_min…amount_max.

Coming to think of it, recipe.results is an array, so if different mods modify the same recipe, it could end up like this:

Code: Select all

{
    {'apple', 1},
    {name='apple', amount=2},
    
    {name='pear', amount=42, catalyst_amount=28},
    {name='pear', amount=24, probability=0.5},
    {name='pear', amount=11, probability=0.3},
}
How would that be combined?

Code: Select all

-- Entries of corresponding results are merged, values with the same name are added
{
    {name='apple', amount=3},
    {name='pear', amount=77, catalyst_amount=28, probability=0.8},
}

-- Entries of corresponding results are merged, values with the same name are averaged (rounded down)
{
    {name='apple', amount=1},
    {name='pear', amount=77, catalyst_amount=28, probability=0.8},
    {name='pear', amount=42, catalyst_amount=math.floor(28 / 3), probability=math.floor( ( (0.8*10) / 3) / 10},
}


-- Entries of corresponding results are merged, values with the same name are averaged (rounded up)
{
    {name='apple', amount=2},
    {name='pear', amount=42, catalyst_amount=math.ceil(28 / 3), probability=math.ceil( ( (0.8*10) / 3) / 10},
}

-- Entries of corresponding results are merged, optional values from later entries will overwrite those from earlier ones
{
    {name='apple', amount=3},
    {name='pear', amount=77, catalyst_amount=28, probability=0.3},
}
 
-- Entries of corresponding results are merged unless they differ in regard to optional values
{
    {name='apple', amount=3},
    -- Result in game: 14 … (14+24+11)
    {name='pear', amount=42, catalyst_amount=28},
    {name='pear', amount=24, probability=0.5},
    {name='pear', amount=11, probability=0.3},
}   
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
Silari
Filter Inserter
Filter Inserter
Posts: 490
Joined: Sat Jan 27, 2018 10:04 pm
Contact:

Re: Small documentation improvement requests

Post by Silari »

Far as I've seen the game doesn't merge recipe results if it includes the same item multiple times. You just end up with a slot for each of the individual outputs.

Code: Select all

results = {{type="item",name="wood",amount=1},
               {type="item",name="wood",amount=1},
               {type="item",name="wood",amount=1},
               {type="item",name="wood",amount=1},
               {type="item",name="wood",amount=1}}
  }
gives you 1 wood in each of five output slots. I can't imagine specifying min or max would change that.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1651
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Small documentation improvement requests

Post by Pi-C »

Silari wrote:
Mon Apr 26, 2021 2:12 am
Far as I've seen the game doesn't merge recipe results if it includes the same item multiple times. You just end up with a slot for each of the individual outputs.

Code: Select all

results = {{type="item",name="wood",amount=1},
               {type="item",name="wood",amount=1},
               {type="item",name="wood",amount=1},
               {type="item",name="wood",amount=1},
               {type="item",name="wood",amount=1}}
  }
gives you 1 wood in each of five output slots.
You're right. I just made a quick mock-up using the results from my example (replaced "apple" and "pear" with vanilla items):
prototype_viewer.png
prototype_viewer.png (118.13 KiB) Viewed 2331 times
Details for every result item will be visible per default!
Details for every result item will be visible per default!
same_results_recipe.png (52.18 KiB) Viewed 2331 times
I can't imagine specifying min or max would change that.
Then I made this change

Code: Select all

    -- {name='pear', amount=42, catalyst_amount=28},
    {name='wood', amount=20, amount_min=28, amount_max=42, catalyst_amount=28},
and got:
prototype_viewer_-_override.png
prototype_viewer_-_override.png (115.41 KiB) Viewed 2331 times
So, if "amount" is set, it will overwrite both amount_min and amount_max; and each time an item is used, it will show up in the results list. Don't you agree it would be useful to have this info in the description?
Last edited by Pi-C on Mon Apr 26, 2021 7:37 am, edited 1 time in total.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Bilka
Factorio Staff
Factorio Staff
Posts: 3130
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Discussion about recipe result formats

Post by Bilka »

Note: Posts split from 97880
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Bilka
Factorio Staff
Factorio Staff
Posts: 3130
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Discussion about recipe result formats

Post by Bilka »

Pi-C wrote:
Mon Apr 26, 2021 7:00 am
So, if "amount" is set, it will overwrite both amount_min and amount_max; and each time an item is used, it will show up in the results list. Don't you agree it would be useful to have this info in the description?
Something interesting about the highlighted part: That is only the case for results, for ingredients having multiples of the same item/fluid is not allowed (= prototype error on load). All this has been noted on the wiki.

The reasoning behind this behaviour is mostly explained at viewtopic.php?f=11&t=67857#p420038 for anyone curious.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1651
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Discussion about recipe result formats

Post by Pi-C »

Bilka wrote:
Mon Apr 26, 2021 7:49 am
Pi-C wrote:
Mon Apr 26, 2021 7:00 am
So, if "amount" is set, it will overwrite both amount_min and amount_max; and each time an item is used, it will show up in the results list. Don't you agree it would be useful to have this info in the description?
Something interesting about the highlighted part: That is only the case for results, for ingredients having multiples of the same item/fluid is not allowed (= prototype error on load). All this has been noted on the wiki.
Thanks! :-)
The reasoning behind this behaviour is mostly explained at viewtopic.php?f=11&t=67857#p420038 for anyone curious.
Interesting reading …
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 discussion”