Page 1 of 1

reset_recipes is not working

Posted: Mon Jul 11, 2016 4:05 pm
by KroshkaYenot
Hi!

I've added a new recipe. After Factorio restart, it's not visible.
AFAIK I should reset recipes by typing in the console (I know about migrations)

Code: Select all

/c game.player.force.reset_recipes()
I did it but without any success

Code: Select all

/c game.player.force.reset_technologies()
Is not working for me as well. But

Code: Select all

game.player.force.technologies["TECHNOLOGYNAME"].researched = false
game.player.force.technologies["TECHNOLOGYNAME"].researched = true
works fine. What I'm doing wrong ?

version 0.13.6-0.13.7
I'm not sure, but as far as I remember reset_recipes() worked fine in 0.13.5

Re: reset_recipes is not working

Posted: Mon Jul 11, 2016 5:14 pm
by orzelek
Is your recipe set to enabled by default?

Re: reset_recipes is not working

Posted: Mon Jul 11, 2016 5:22 pm
by KroshkaYenot
No. According to this

https://wiki.factorio.com/index.php?tit ... ype/Recipe
enabled
Type: Types/string (!)
Optional. This can be "false" to disable the recipe at the start of the game, or "true" to leave it enabled. The default is "true".
If your recipe is unlocked by a technology, you should set this to "false".

Re: reset_recipes is not working

Posted: Mon Jul 11, 2016 5:23 pm
by orzelek
KroshkaYenot wrote:No. According to this

https://wiki.factorio.com/index.php?tit ... ype/Recipe
enabled
Type: Types/string (!)
Optional. This can be "false" to disable the recipe at the start of the game, or "true" to leave it enabled. The default is "true".
If your recipe is unlocked by a technology, you should set this to "false".
Do try to add the attribute. Things change sometimes :D

Re: reset_recipes is not working

Posted: Mon Jul 11, 2016 6:45 pm
by KroshkaYenot
It's set to "false"

enabled = "false"

So its not enabled by default. It's disabled because it's unlocked by a technology

Re: reset_recipes is not working

Posted: Mon Jul 11, 2016 7:05 pm
by DedlySpyder
KroshkaYenot wrote:It's set to "false"

enabled = "false"

So its not enabled by default. It's disabled because it's unlocked by a technology
Is it showing up under the technology at all? If it's not in an old world check a brand new world's tech tree. If it's not showing up there then something is wrong with the prototype

Re: reset_recipes is not working

Posted: Mon Jul 11, 2016 7:40 pm
by orzelek
KroshkaYenot wrote:It's set to "false"

enabled = "false"

So its not enabled by default. It's disabled because it's unlocked by a technology
Are you expecting for it to show up in recipes after reset calls?
Those only reload the recipes/technologies to update save data to current state. They won't research the tech so no recipe is visible.

Unless it's not showing under that technology after reset technologies call - then it's a bug for bug forums.

Re: reset_recipes is not working

Posted: Tue Jul 12, 2016 1:54 pm
by KroshkaYenot
I forked old mod "Boxing" by Xecutor. There are already few recipes: pack electronics, iron ore and few more. So I'm pretty sure there is everything ok with prototypes.

When I was on 0.13.5, I've added a new recipe "Pack stone". I don't really remember what spells did I use, but magic was successful. AFAIR it was /c game.player.force.reset_recipes(). So I've seen my first improvement.

Then I upgraded to 0.13.6-0.13.8 and added one more recipe "Pack gears". The technology itself has already been researched. So I can see other recipes this technology unlocks, but I can't see my "Pack gears"

I put a spell

Code: Select all

/c game.player.force.reset_recipes()
and even

Code: Select all

/c game.player.force.reset_technologies()
without any success. And only this black magic

Code: Select all

/c game.player.force.technologies["TECHNOLOGYNAME"].researched = false
/c game.player.force.technologies["TECHNOLOGYNAME"].researched = true
did the job, but switching researched on and off is not really suitable for migrations. Thanks to you, comrades, I started to think there is a bug in Factorio wich prevents me from seeing my lovely recipe and makes me suffer. But before posting a bug report, I'd like to be sure. Here is a video

Re: reset_recipes is not working

Posted: Tue Jul 12, 2016 2:47 pm
by DedlySpyder
We understand your process of what you are doing. Now, is the new recipe showing up under the technology? If it's not then please provide the code for the technology prototype

Re: reset_recipes is not working

Posted: Tue Jul 12, 2016 3:02 pm
by KroshkaYenot
is the new recipe showing up under the technology?
Yes it is. But only after switching "researched" for this technology off and back on

Here is the code. Full mod is in the attachment

Code: Select all


data:extend{
  {
    type = "recipe",
    name = "steel-box",
    energy_required = 0.5,
    ingredients =
    {
      {"steel-plate", 1},
      {"plastic-bar",1}
    },
    result = "steel-box",
    enabled = "false"
  },
  {
    type = "recipe",
    name = "boxed-electronic-circuits",
    icon = "__boxing__/graphics/icons/boxed-electronic-circuits.png",
    subgroup = "boxing",
    order = "v[box]-a[empty]",
    energy_required = 90,
    category = "advanced-crafting",
    ingredients =
    {
      {"box-of-iron-plate", 2},
      {"box-of-copper-cable",3}
    },
    results = {
      {"box-of-electronic-circuit",1},
      {"steel-box",4}
    },
    enabled = "false"
  },
  {
    type = "recipe",
    name = "boxed-advanced-circuits",
    icon = "__boxing__/graphics/icons/boxed-advanced-circuits.png",
    subgroup = "boxing",
    order = "w[box]-a[empty]",
    category = "advanced-crafting",
    energy_required = 700,
    ingredients =
    {
      {"box-of-electronic-circuit", 1},
      {"box-of-plastic-bar",2},
      {"box-of-copper-cable",2},
    },
    results = {
      {"box-of-advanced-circuit",1},
      {"steel-box",4}
    },
    enabled = "false"
  },
  {
    type = "item",
    name = "steel-box",
    flags = {"goes-to-main-inventory"},
    icon = "__boxing__/graphics/icons/steel-box.png",
    subgroup = "boxing",
    order = "a[box]-a[empty]",
    stack_size = 10
  },
  {
    type = "item-subgroup",
    name = "boxing",
    group = "intermediate-products",
    order = "db"
  },
}

local itemsToBeBoxed={
  {
    name='coal',
    count=50,
    boxorder='b',
    unboxorder='c'
  },
  {
    name='iron-ore',
    count=50,
    boxorder='d',
    unboxorder='e'
  },
  {
    name='copper-ore',
    count=50,
    boxorder='f',
    unboxorder='g'
  },
  {
    name='iron-plate',
    count=100,
    boxorder='h',
    unboxorder='i'
  },
  {
    name='copper-plate',
    count=100,
    boxorder='j',
    unboxorder='k'
  },
  {
    name='copper-cable',
    count=200,
    boxorder='l',
    unboxorder='m'
  },
  {
    name='electronic-circuit',
    count=200,
    boxorder='n',
    unboxorder='o'
  },
  {
    name='plastic-bar',
    count=100,
    boxorder='p',
    unboxorder='q',
    adv=true
  },
  {
    name='steel-plate',
    count=100,
    boxorder='r',
    unboxorder='s',
    adv=true
  },
  {
    name='advanced-circuit',
    count=100,
    boxorder='t',
    unboxorder='u',
    adv=true
  },
  {
    name='stone',
    count=50,
    boxorder='v',
    unboxorder='w'
  },
  {
    name='iron-gear-wheel',
    count=100,
    boxorder='x',
    unboxorder='y'
  }
}

local boxingEffects={
  {
    type = "unlock-recipe",
    recipe = "steel-box"
  },
}

local advBoxingEffects={
  {
    type = "unlock-recipe",
    recipe = "boxed-electronic-circuits"
  },
  {
    type = "unlock-recipe",
    recipe = "boxed-advanced-circuits"
  },
}


for i=1,#itemsToBeBoxed do
  local item=itemsToBeBoxed[i]
  local name=item.name
  local count=item.count
  local boxorder=item.boxorder
  local unboxorder=item.unboxorder
  data:extend{
    {
      type = "recipe",
      name = "box-"..name,
      energy_required = 1,
      category = "advanced-crafting",
      subgroup = "boxing",
      order = boxorder.."[box-"..name.."]",
      ingredients =
      {
        {name, count},
        {"steel-box", 1},
      },
      icon = "__boxing__/graphics/icons/box-"..name..".png",
      result = "box-of-"..name,
      enabled = "false"
    },
    {
      type = "recipe",
      name = "unbox-"..name,
      category = "advanced-crafting",
      energy_required = 1,
      subgroup = "boxing",
      order = unboxorder.."[ubox-"..name.."]",
      enabled = "false",
      icon = "__boxing__/graphics/icons/unbox-"..name..".png",
      ingredients =
      {
        {type="item", name="box-of-"..name, amount=1}
      },
      results=
      {
       {type="item", name=name, amount=count},
        {type="item", name="steel-box", amount=1}
      }
    },
    {
      type = "item",
      flags = {"goes-to-main-inventory"},
      name = "box-of-"..name,
      icon = "__boxing__/graphics/icons/box-of-"..name..".png",
      subgroup = "boxing",
      order = "b[box]-"..boxorder.."["..name.."]",
      stack_size = 10
    },
  }
  if not item.adv then
    table.insert(boxingEffects,
    {
      type = "unlock-recipe",
      recipe = "box-"..name
    })
    table.insert(boxingEffects,
    {
      type = "unlock-recipe",
      recipe = "unbox-"..name
    })
  else
    table.insert(advBoxingEffects,
    {
      type = "unlock-recipe",
      recipe = "box-"..name
    })
    table.insert(boxingEffects,
    {
      type = "unlock-recipe",
      recipe = "unbox-"..name
    })
  end
end


data:extend{
  {
    type = "technology",
    name = "boxing",
    icon = "__boxing__/graphics/icons/boxing-tech.png",
    prerequisites = {"logistics-3"},
    unit =
    {
      count = 150,
      ingredients =
      {
        {"science-pack-1", 1},
        {"science-pack-2", 1},
        {"science-pack-3", 1}
      },
      time = 30
    },
    effects = boxingEffects,
    order = "d-e",
  },
  {
    type = "technology",
    name = "boxing2",
    icon = "__boxing__/graphics/icons/boxing-tech2.png",
    prerequisites = {"boxing"},
    unit =
    {
      count = 200,
      ingredients =
      {
        {"science-pack-1", 1},
        {"science-pack-2", 1},
        {"science-pack-3", 1}
      },
      time = 30
    },
    effects = advBoxingEffects,
    order = "d-f",
  },
}

Re: reset_recipes is not working

Posted: Tue Jul 12, 2016 4:35 pm
by DedlySpyder
Have you tried reseting the technologies first, then the recipes? I just noticed that you did it backwards in the gif

Re: reset_recipes is not working

Posted: Tue Jul 12, 2016 5:17 pm
by orzelek
When you are updating mod and chaning technology you need to use migration to correct for this.
You don't need to change technology itself - it's enough to check in migration script if technology is researched and enable/disable the recipe based on that.

Re: reset_recipes is not working

Posted: Tue Jul 12, 2016 5:23 pm
by KroshkaYenot
Have you tried reseting the technologies first, then the recipes?
Yes. Any order has no effect.
it's enough to check in migration script if technology is researched and enable/disable the recipe based on that.
Good idea. Thanks. But am I correct: is this a bug with reset_technologies() not working ?

Re: reset_recipes is not working

Posted: Tue Jul 12, 2016 5:48 pm
by orzelek
KroshkaYenot wrote:
Have you tried reseting the technologies first, then the recipes?
Yes. Any order has no effect.
it's enough to check in migration script if technology is researched and enable/disable the recipe based on that.
Good idea. Thanks. But am I correct: is this a bug with reset_technologies() not working ?
It is not. If recipe is listed on technology then it works as advertised I think. It's meant to read technology changes not apply them retroactively.

Re: reset_recipes is not working

Posted: Tue Jul 12, 2016 7:02 pm
by DedlySpyder
Gah, that's right! Reset_recipes doesn't enable a recipe, it just updates the prototype. You need to have specific code to enable it (I believe it has to be in the on_configuration_changed event because you need to access the force)

Re: reset_recipes is not working

Posted: Tue Jul 12, 2016 7:33 pm
by KroshkaYenot
Ugrhhhh.... Such a rocket science!

Thanks to your advices I've found that following migration properly turns everything on in my old test saves

Code: Select all

for _,player in pairs(game.players) do
	player.force.reset_recipes()
	player.force.reset_technologies()
end


for index, force in pairs(game.forces) do
	if force.technologies["boxing"].researched then
		force.recipes["box-iron-gear-wheel"].enabled = true
		force.recipes["unbox-iron-gear-wheel"].enabled = true
	end
end