reset_recipes is not working

Place to get help with not working mods / modding interface.
User avatar
KroshkaYenot
Inserter
Inserter
Posts: 27
Joined: Tue Jun 28, 2016 6:49 am
Contact:

reset_recipes is not working

Post 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
orzelek
Smart Inserter
Smart Inserter
Posts: 3928
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: reset_recipes is not working

Post by orzelek »

Is your recipe set to enabled by default?
User avatar
KroshkaYenot
Inserter
Inserter
Posts: 27
Joined: Tue Jun 28, 2016 6:49 am
Contact:

Re: reset_recipes is not working

Post 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".
orzelek
Smart Inserter
Smart Inserter
Posts: 3928
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: reset_recipes is not working

Post 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
User avatar
KroshkaYenot
Inserter
Inserter
Posts: 27
Joined: Tue Jun 28, 2016 6:49 am
Contact:

Re: reset_recipes is not working

Post 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
User avatar
DedlySpyder
Filter Inserter
Filter Inserter
Posts: 254
Joined: Fri Jun 20, 2014 11:42 am
Contact:

Re: reset_recipes is not working

Post 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
orzelek
Smart Inserter
Smart Inserter
Posts: 3928
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: reset_recipes is not working

Post 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.
User avatar
KroshkaYenot
Inserter
Inserter
Posts: 27
Joined: Tue Jun 28, 2016 6:49 am
Contact:

Re: reset_recipes is not working

Post 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
Attachments
factorio33.gif
factorio33.gif (3.92 MiB) Viewed 6252 times
User avatar
DedlySpyder
Filter Inserter
Filter Inserter
Posts: 254
Joined: Fri Jun 20, 2014 11:42 am
Contact:

Re: reset_recipes is not working

Post 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
User avatar
KroshkaYenot
Inserter
Inserter
Posts: 27
Joined: Tue Jun 28, 2016 6:49 am
Contact:

Re: reset_recipes is not working

Post 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",
  },
}
Attachments
boxing_0.6.1.zip
(190.08 KiB) Downloaded 157 times
User avatar
DedlySpyder
Filter Inserter
Filter Inserter
Posts: 254
Joined: Fri Jun 20, 2014 11:42 am
Contact:

Re: reset_recipes is not working

Post by DedlySpyder »

Have you tried reseting the technologies first, then the recipes? I just noticed that you did it backwards in the gif
orzelek
Smart Inserter
Smart Inserter
Posts: 3928
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: reset_recipes is not working

Post 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.
User avatar
KroshkaYenot
Inserter
Inserter
Posts: 27
Joined: Tue Jun 28, 2016 6:49 am
Contact:

Re: reset_recipes is not working

Post 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 ?
orzelek
Smart Inserter
Smart Inserter
Posts: 3928
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: reset_recipes is not working

Post 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.
User avatar
DedlySpyder
Filter Inserter
Filter Inserter
Posts: 254
Joined: Fri Jun 20, 2014 11:42 am
Contact:

Re: reset_recipes is not working

Post 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)
User avatar
KroshkaYenot
Inserter
Inserter
Posts: 27
Joined: Tue Jun 28, 2016 6:49 am
Contact:

Re: reset_recipes is not working

Post 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
Post Reply

Return to “Modding help”