bobmods.lib.add_recipe_item changed in 0.13?

Some mods, made by Bob. Basically streaks every Factroio-area.

Moderator: bobingabout

Post Reply
Dilbe
Inserter
Inserter
Posts: 23
Joined: Fri Jun 03, 2016 10:19 am
Contact:

bobmods.lib.add_recipe_item changed in 0.13?

Post by Dilbe »

I used to use the following code in a mod to make modules more expensive, but this does not work anymore in 0.13.
bobmods.lib.add_recipe_item("productivity-module-2", {"productivity-module", 1})
bobmods.lib.add_recipe_item("productivity-module-4", {"productivity-module-3", 1})
bobmods.lib.add_recipe_item("productivity-module-5", {"productivity-module-4", 1})
bobmods.lib.add_recipe_item("productivity-module-7", {"productivity-module-6", 1})
bobmods.lib.add_recipe_item("productivity-module-8", {"productivity-module-7", 1})

Did the function bobmods.lib.add_recipe_item change in 0.13? If so, is there a different function i can use to add ingredients to a recipe?

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: bobmods.lib.add_recipe_item changed in 0.13?

Post by bobingabout »

It was replaced with

Code: Select all

bobmods.lib.recipe.add_ingredient(recipe, item)
However, there is a legacy include that translates that to the old name.

It should still just function as before.


Without further information about what it is or isn't doing, I can't help.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

Dilbe
Inserter
Inserter
Posts: 23
Joined: Fri Jun 03, 2016 10:19 am
Contact:

Re: bobmods.lib.add_recipe_item changed in 0.13?

Post by Dilbe »

Thank you for the reply, Bob.

In version 0.12 this piece of code:
bobmods.lib.add_recipe_item("productivity-module-2", {"productivity-module", 1})
made the productivity module 2 require 2 productivity modules 1 as input to make. So to make 1 productivity module 2, you'd need 2 productivity 1. (instead of the 1 it would normally require without that code).

In 0.13 the productivty 2 module now still only requires 1 productivity module 1. Even if i change it to:
bobmods.lib.add_recipe_item("productivity-module-2", {"productivity-module", 2})
It then still only requires 1 productivty module 1.

edit: replacing add_recipe_item with recipe.add_ingredient still didn't make it work as i expected )-:

Dilbe
Inserter
Inserter
Posts: 23
Joined: Fri Jun 03, 2016 10:19 am
Contact:

Re: bobmods.lib.add_recipe_item changed in 0.13?

Post by Dilbe »

I see that the function has been changed and I found the problem for me.

If i change

Code: Select all

function bobmods.lib.item.add(list, item_in) --increments amount if exists
  local item = bobmods.lib.item.item(item_in)
  local addit = true
  for i, object in pairs(list) do
    if object[1] == item.name or object.name == item.name then
      addit = false
      object = bobmods.lib.item.combine(object, item)
    end
  end
  if addit then table.insert(list, item) end
end
to

Code: Select all

function bobmods.lib.item.add(list, item_in) --increments amount if exists
  local item = bobmods.lib.item.item(item_in)
  local addit = true
  for i, object in pairs(list) do
    if object[1] == item.name or object.name == item.name then
      addit = false
      object = bobmods.lib.item.combine(object, item_in)
      list[i] = object
    end
  end
  if addit then table.insert(list, item) end
end
Then it works the way i expect it too work.

I made 2 changes, the amount to increment with was not passed onto bobmods.lib.item.combine, because it passed item, instead of item_in. And the result object was not used in the input recipe list, so i overrode the old ingredient with the result from bobmods.lib.item.combine.

I'm not sure if this is a bug or if i am trying to use it for something it is not meant for, so i added a copy of the old 0.12 function to my own mod, and now i have what i want (-: So i'm happy.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: bobmods.lib.add_recipe_item changed in 0.13?

Post by bobingabout »

Hmm, it's odd that your version works and mine doesn't.


item is just item_in restructured, for the purpose of passing to the combine function, they should be the same thing.

in the object in pairs(list) loop, object should be a pointer to list, not a copy of it, therefore writing back to object should automatically write back to list at the same time. This second part though may be the issue, if I simply replace object with list as the save point in the line that calls the combine function, then it should fix the issue.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

Dilbe
Inserter
Inserter
Posts: 23
Joined: Fri Jun 03, 2016 10:19 am
Contact:

Re: bobmods.lib.add_recipe_item changed in 0.13?

Post by Dilbe »

Your right, passing item works, item_in is not needed. Changing only the thing you said also fixes it. So then the code would be

Code: Select all

function bobmods.lib.item.add(list, item_in) --increments amount if exists
  local item = bobmods.lib.item.item(item_in)
  local addit = true
  for i, object in pairs(list) do
    if object[1] == item.name or object.name == item.name then
      addit = false
      list[i] = bobmods.lib.item.combine(object, item)
    end
  end
  if addit then table.insert(list, item) end
end
In normal object oriented programming that would be what i expect, because you replace the pointer, not the value the pointer points to.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: bobmods.lib.add_recipe_item changed in 0.13?

Post by bobingabout »

I have made the same change myself... but there are other WIP things in my current version, so it will just get added to my WIP changelog for now.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

Post Reply

Return to “Bob's mods”