Page 1 of 1
Recipe output probabilities - how does it work?
Posted: Mon Sep 02, 2019 5:14 pm
by Trblz
I want the output of my recipe
products to work as followed using probabilities. Here's an example where the main product has 80% probability ("chance to succeed") and 20% probability to fail.
Code: Select all
results =
{
{type="item", name="main-product", probability=0.8, amount=1}, --this is the main product with 80% probability to succeed
{type="item", name="by-product1", probability=0.2, amount=1}
}
this works as expected.
Now here's an more complex example. The principle is still 80% for main-product and 20% for by-products.
Code: Select all
results =
{
{type="item", name="main-product", probability=1.6, amount=1}, --this is the main product with 80% probability to succeed
{type="item", name="by-product1", probability=0.2, amount=1},
{type="item", name="by-product3", probability=0.2, amount=1},
{type="fluid", name="by-product4", probability=0.2, amount=1}
}
If i do this using
Amator Phasma's Recycling, i get
![Untitled.png](./download/file.php?id=53213)
- Untitled.png (267.84 KiB) Viewed 3891 times
What i don't get is that the main product needs a probability of 1.6 (160%) in order to get the 80%/20%/20%/20%?
Is the probability set per recipe or item category?
Re: Recipe output probabilities - how does it work?
Posted: Mon Sep 02, 2019 5:36 pm
by eradicator
https://wiki.factorio.com/Types/ItemProductPrototype
Product probabilities are calculated individually per cycle for each product. I.e. having one product with 80% and one with 20% means there's still a 0.2*0.8 = 16% chance of getting both in the same cycle. Probability has to be a value between 0 and 1 (see link above).
I can't help you with the recycling mod or it's bugs because i don't know it, but...
What do you even mean by "using" it? Are you using functions from the mod to generate your recipe?
Re: Recipe output probabilities - how does it work?
Posted: Mon Sep 02, 2019 6:39 pm
by Trblz
I am using the mod library as a bases for my own changes. The good thing of this lib is that i don't have to create a full library of new items.
The recipes are added through the following procedure (in recipe.lua)
Code: Select all
function apm.lib.utils.recipe.result.add_with_probability(recipe_name, result_name, result_amount_min, result_amount_max, probability)
local recipe = data.raw.recipe[recipe_name]
local type_name = apm.lib.utils.item.get_type(result_name)
-- convert result
apm.lib.utils.recipe.convert_simple_result_to_results(recipe_name)
-- simple recipe (results)
if recipe.results then
table.insert(recipe.results,{type=type_name, name=result_name, amount_min=result_amount_min, amount_max=result_amount_max, probability=probability})
end
apm.lib.utils.recipe.add_mainproduct_if_needed(recipe_name)
end
So the mod is only doing a table insert using it's own library function set.
Product probabilities are calculated individually per cycle for each product. I.e. having one product with 80% and one with 20% means there's still a 0.2*0.8 = 16% chance of getting both in the same cycle. Probability has to be a value between 0 and 1 (see link above).
This part i get and i am not challenging it. At it works in my simple example.
What i am challenging is that i need to put 1.6 (160%) for the red circuit to get an actual 80% chance as reported in the screenshot.
Re: Recipe output probabilities - how does it work?
Posted: Mon Sep 02, 2019 7:13 pm
by Deadlock989
Trblz wrote: Mon Sep 02, 2019 6:39 pm
What i am challenging is that i need to put 1.6 (160%) for the red circuit to get an actual 80% chance as reported in the screenshot.
I have a bunch of recipes which produce a big mixed bag of results, some probabilistic, some not, and I don't observe that behaviour (and have counted results). If it says probability = 0.75, I get it 75% of the time. I'm not sure what 160% even means for an ItemProductPrototype. The wiki currently suggests it is supposed to be a 0-1 value.
Re: Recipe output probabilities - how does it work?
Posted: Mon Sep 02, 2019 7:22 pm
by Trblz
Following your comment about probability in the 0 - 1 range
If i use:
Code: Select all
results =
{
{type="item", name="main-product", probability=0.8, amount=1}, --this is the main product with 80% probability to succeed
{type="item", name="by-product1", probability=0.2, amount=1},
{type="item", name="by-product3", probability=0.2, amount=1},
{type="fluid", name="by-product4", probability=0.2, amount=1}
}
then it displays as
40%/20%/20%/20%
Re: Recipe output probabilities - how does it work?
Posted: Mon Sep 02, 2019 7:37 pm
by Deadlock989
Not for me. Sounds like some other mod is dicking with your recipes.
Re: Recipe output probabilities - how does it work?
Posted: Mon Sep 02, 2019 7:43 pm
by darkfrei
Add Amator Phasma's Recycling to dependencies or shift the code to the one data file later. From data.lua to data-updates.lua or from data-updates.lua to data-final-fixes.lua
Re: Recipe output probabilities - how does it work?
Posted: Mon Sep 02, 2019 7:47 pm
by eradicator
Trblz wrote: Mon Sep 02, 2019 7:22 pm
then it displays as
40%/20%/20%/20%
Certainly sounds like a problem with the library your using and not with the game itself. Try using data:extend{} for comparison, if that works you can be sure it's a problem with the library.
darkfrei wrote: Mon Sep 02, 2019 7:43 pm
Add Amator Phasma's Recycling to dependencies or shift the code to the one data file later. From data.lua to data-updates.lua or from data-updates.lua to data-final-fixes.lua
Or try that. I have no knowledge about how to use that particular library.
Re: Recipe output probabilities - how does it work?
Posted: Mon Sep 02, 2019 8:02 pm
by darkfrei
I use for such situation the Info Mod
viewtopic.php?f=135&t=45107, that writes the whole data.raw to log file and you can see all parameters after all applying code of all other mods.