[SOLVED]Updating research not working

Place to get help with not working mods / modding interface.
Post Reply
vlczero
Inserter
Inserter
Posts: 47
Joined: Sun Oct 05, 2014 1:51 pm
Contact:

[SOLVED]Updating research not working

Post by vlczero »

Hi,
For my mod Tankwerkz i am adding additional effects to vanilla research and this works when starting a new game, but does not for a existing save that already has the research unlocked.

Adding additional effect to bullet-damage-1:

Code: Select all

data.raw["technology"]["bullet-damage-1"].effects[2] = 
{
  type = "ammo-damage",
  ammo_category = "heavy-mg",
  modifier = "0.1"
}
Migration file:

Code: Select all

game.reload_script()

for index, force in pairs(game.forces) do
  force.reset_recipes()
  force.reset_technologies()
end
I also tested

Code: Select all

game.reload_script()

for index, force in pairs(game.forces) do
  force.reset_recipes()
  force.reset_technologies()
  
  local technologies = force.technologies;

  technologies["bullet-damage-1"].reload()
end
But this is also not working.

Does anyone know what i am doing wrong here?
Last edited by vlczero on Tue Jul 05, 2016 7:56 am, edited 1 time in total.

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Updating research not working

Post by prg »

Maybe you could just see if the technology is already researched, then run set_ammo_damage_modifier manually.

Also,
vlczero wrote:

Code: Select all

data.raw["technology"]["bullet-damage-1"].effects[2] = 
{
  type = "ammo-damage",
  ammo_category = "heavy-mg",
  modifier = "0.1"
}
if another mod did the same thing, one would overwrite the other one's changes, better use table.insert() here.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

vlczero
Inserter
Inserter
Posts: 47
Joined: Sun Oct 05, 2014 1:51 pm
Contact:

Re: Updating research not working

Post by vlczero »

prg wrote:Maybe you could just see if the technology is already researched, then run set_ammo_damage_modifier manually.

Also,
vlczero wrote:

Code: Select all

data.raw["technology"]["bullet-damage-1"].effects[2] = 
{
  type = "ammo-damage",
  ammo_category = "heavy-mg",
  modifier = "0.1"
}
if another mod did the same thing, one would overwrite the other one's changes, better use table.insert() here.

Thx for the tip on set_ammo_damage_modifier and table.insert

The working migration:

Code: Select all

for index, force in pairs(game.forces) do
  local technologies = force.technologies;

  local researchList = {
    { research_name = "bullet-damage", ammo_category = "heavy-mg", modifiers = {0.1, 0.1, 0.2, 0.2, 0.2, 0.4 }},
    { research_name = "rocket-damage", ammo_category = "hydra-rocket", modifiers = {0.1, 0.1, 0.2, 0.2, 0.2 }},
    { research_name = "flamethrower-damage", ammo_category = "tank-flame-thrower", modifiers = {0.1, 0.1, 0.2, 0.2, 0.2, 0.4 }}
  }

  for v, item in pairs(researchList) do
    for k, modifier in ipairs(item.modifiers) do
      name = item.research_name .. "-" .. k
      if technologies[name].researched then
        force.set_ammo_damage_modifier(item.ammo_category , force.get_ammo_damage_modifier(item.ammo_category) + modifier)
      end
    end
  end

end

Post Reply

Return to “Modding help”