Page 1 of 1

Discussion about recipe result formats

Posted: Sun Apr 25, 2021 9:18 pm
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}

Re: Small documentation improvement requests

Posted: Mon Apr 26, 2021 12:57 am
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},
}   

Re: Small documentation improvement requests

Posted: Mon Apr 26, 2021 2:12 am
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.

Re: Small documentation improvement requests

Posted: Mon Apr 26, 2021 7:00 am
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 2352 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 2352 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 2352 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?

Re: Discussion about recipe result formats

Posted: Mon Apr 26, 2021 7:16 am
by Bilka
Note: Posts split from 97880

Re: Discussion about recipe result formats

Posted: Mon Apr 26, 2021 7:49 am
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.

Re: Discussion about recipe result formats

Posted: Mon Apr 26, 2021 8:05 am
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 …