productivity_bonus loss problem

Place to get help with not working mods / modding interface.
Xeon257
Long Handed Inserter
Long Handed Inserter
Posts: 60
Joined: Wed Sep 24, 2025 6:25 pm
Contact:

productivity_bonus loss problem

Post by Xeon257 »

Hello. I am trying to implement a feature by controlling LuaRecipe's productivity_bonus as shown below.

Code: Select all

recipes["dps-ammo_apfsds-shell_"..i].productivity_bonus = probability_0001 * (total_probability - ptyp.main_product.shared_probability.max) * 100000
However, it seems there is an issue where this value is initialized based on specific conditions. Is there a special condition under which this value is initialized?
I am not able to write in English myself, so I am using ChatGPT for help. Please excuse any awkward phrasing.
Rseding91
Factorio Staff
Factorio Staff
Posts: 17454
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: productivity_bonus loss problem

Post by Rseding91 »

When technology effects are reset those values are reset to 0 and calculated using the technology effects.
If you want to get ahold of me I'm almost always on Discord.
Xeon257
Long Handed Inserter
Long Handed Inserter
Posts: 60
Joined: Wed Sep 24, 2025 6:25 pm
Contact:

Re: productivity_bonus loss problem

Post by Xeon257 »

I'm sorry. Could you please be a little more specific?
I am not able to write in English myself, so I am using ChatGPT for help. Please excuse any awkward phrasing.
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 4837
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: productivity_bonus loss problem

Post by boskid »

If you want more specific answers, please ask more specific questions and show more code that is not working. Right now this topic looks like a puzzle in itself and so do not expect precise answers.
Xeon257
Long Handed Inserter
Long Handed Inserter
Posts: 60
Joined: Wed Sep 24, 2025 6:25 pm
Contact:

Re: productivity_bonus loss problem

Post by Xeon257 »

The full text of the function is as follows.

Code: Select all

local function _research_update(e)
  if e.research.name == "dps-tech_advanced-apfsds-shell-enhancement-chance" or
      e.research.name == "dps-tech_advanced-apfsds-shell-destruction-protection" then
        
    local force = game.forces["player"]
    local tech = force.technologies
    local recipes = force.recipes

    local lv_ec = tech["dps-tech_advanced-apfsds-shell-enhancement-chance"].level - 1
    if tech["dps-tech_advanced-apfsds-shell-enhancement-chance"].researched then
      lv_ec = lv_ec + 1
    end

    local lv_dp = tech["dps-tech_advanced-apfsds-shell-destruction-protection"].level - 1
    if tech["dps-tech_advanced-apfsds-shell-destruction-protection"].researched then
      lv_dp = lv_dp + 1
    end

    local addition_probability = lv_ec * 0.01
    local protection_probability = lv_dp * 0.05

    for i = 6, 10, 1 do
      local ptyp = recipes["dps-ammo_apfsds-shell_"..i].prototype
      local probability = ptyp.main_product.shared_probability.max + addition_probability
      local total_probability = probability / (1 - (1 - probability) * protection_probability)

      local probability_0001 = 1.0 / (ptyp.main_product.shared_probability.max * 100000)

      recipes["dps-ammo_apfsds-shell_"..i].productivity_bonus = probability_0001 * (total_probability - ptyp.main_product.shared_probability.max) * 100000
    end
  end
end
I am not sure how to phrase this question. Currently, the recipe in question is not affected by the Technology Effect or other systems. It is possible that I simply failed to discover a bug in my code.

Therefore, if there are specific conditions under which that value is initialized or disabled, I would like to know them. Then, I think I will be able to determine for sure whether the problem is due to a bug or my failure to respond to the relevant conditions.

The mod currently causing the problem is Planet DPS.
I am not able to write in English myself, so I am using ChatGPT for help. Please excuse any awkward phrasing.
Xeon257
Long Handed Inserter
Long Handed Inserter
Posts: 60
Joined: Wed Sep 24, 2025 6:25 pm
Contact:

Re: productivity_bonus loss problem

Post by Xeon257 »

I apologize. When I checked the Lua object with gvv, I found that the level of the referenced LuaTechnology object was initialized to 1. I have no idea what is modifying this or why... I will look into this further.
I am not able to write in English myself, so I am using ChatGPT for help. Please excuse any awkward phrasing.
Post Reply

Return to “Modding help”