Recipe categories

Place to get help with not working mods / modding interface.
Post Reply
User avatar
Phakx
Inserter
Inserter
Posts: 32
Joined: Sun Sep 07, 2014 8:57 pm
Contact:

Recipe categories

Post by Phakx »

Hey people.
I run into some wierd thing in my opinion. If i coded a recipe like for a sub machine gun there is enabled = false for default. If i add a new crafting category for it to be build in one of my new factories it isn't shown up.
This is with every item i do this category. Otherwise if there isn't the enabled =false line everything works fine.
Do i do something wrong?
Oh and btw. my categories work :P

Code: Select all

  {
    type = "recipe",
    name = "submachine-gun",
	category = "military-crafting",
    enabled = "false",
    energy_required = 3,
    ingredients =
    {
      {"iron-gear-wheel", 10},
      {"copper-plate", 5},
      {"iron-plate", 10}
    },
    result = "submachine-gun"
  },
Check out my "TrueBuildings" - Mod

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: Recipe categories

Post by FreeER »

Not exactly. First, just to be sure, enabled = false makes it so that the recipe is not shown by default, if the category is empty (or none of the recipes are enabled) then it won't be displayed. Recipes need to be set enabled during the game (typically with a technology through research, but control.lua/console can unlock it with game.player.force.recipes[recipe_name].enabled = true).

However, I'd imagine the real problem is that assembling machines have a list of categories that they can craft from (specified in prototypes as crafting_categories), so if you want them to be able to craft from your category you'd need to add your category name to their list. something like the following should work:

Code: Select all

for name, prototype in pairs(data.raw["assembling-machine"] do
  if name:find("assembling%-machine") then -- only for assembling-machine types with the text assembling-machine in their name
    table.insert(prototype.crafting_categories, "your_crafting_category_name")
  end
end

User avatar
Phakx
Inserter
Inserter
Posts: 32
Joined: Sun Sep 07, 2014 8:57 pm
Contact:

Re: Recipe categories

Post by Phakx »

So it was false to add my crafting categories in recipe-category.lua?
So i create a new .lua file called "crafting-categories" and leave it blank. So now everything loads but nothing changed.
I really don't know what i'm doing wrong :(

Only to understand this right:
This code you posted inserts a new table inside my crafting-categories.lua so the assembling machine like my "MilitaryBuilder" (this is the factory) could be used to craft the sub-machine-gun if i unlock the research for it. None other assembling machine has the recipe for this weapon anymore?
So i add in my recipe.lua a new category to the "radar" to be only build inside of my MilitaryBuilder.
This is the code for it:

Code: Select all

  {
    type = "recipe",
    name = "radar",
    category = "military-crafting",
    ingredients =
    {
      {"cabling", 10},
      {"iron-gear-wheel", 5},
	  {"iron-stick", 10},
      {"iron-plate", 20},
      {"stone-brick", 20},
    },
    result = "radar"
  },
But if i go into the game it will show me that it is locked and have to be build inside of simething, but it doesn't show me my Builder.
Check out my "TrueBuildings" - Mod

User avatar
Phakx
Inserter
Inserter
Posts: 32
Joined: Sun Sep 07, 2014 8:57 pm
Contact:

Re: Recipe categories

Post by Phakx »

I tried but it didn't show up in my militaryBuilder
Check out my "TrueBuildings" - Mod

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: Recipe categories

Post by FreeER »

for recipes enabled controls whether the recipe will be unlocked at the start of the game or not. If it is set to false (the default is true) then it is not unlocked (and thus not displayed in the crafting menus) and it will need to be unlocked in-game using research (added via a technology prototype, if you need to, see data\base\prototypes\technology\technology.lua). If you want only your military builder entity to be able to craft those recipes then you do need the recipe-category and you also need to add that recipe-category name to the military builder's "crafting_categories" table. The recipe will only not show the crafter if it can be made in anything or if there are no machines with it's category in their "crafting_categories" table. The for loop I shared is designed to add a crafting category name (of "your_crafting_category_name", which should be replaced with whatever you used) to the crafting_categories table of all assembling machines with the text "assembling-machine" in their name, you'd only use it if you wanted other assembling machines to be able to craft those recipes.
heres my test code

User avatar
Phakx
Inserter
Inserter
Posts: 32
Joined: Sun Sep 07, 2014 8:57 pm
Contact:

Re: Recipe categories

Post by Phakx »

I does this. Everything works fine. I create a technology but what my problem is for example the radar. I added the "military-crafting" in my category.lua
In this case if i added category = "military-crafting" node to the radar it should be only be craftable at assembling machines which has the category of "military-crafting".
I don't know why but several items work like the pistol but not the radar. I test it with diffrent items. It doesn't work with everything. Even if i enabled it via technology. If you want i could send you my category and item.lua to check. it just don't show up inside of my builder

EDIT: i added your lower code in a control.lua 2 days ago as you send it to me. but it doesn't solve my problem :( do i have to add it at the item i want to add into my builder? i mean inside of { } it should load from my control.lua
Check out my "TrueBuildings" - Mod

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: Recipe categories

Post by FreeER »

Phakx wrote:EDIT: i added your lower code in a control.lua 2 days ago as you send it to me.
all the code I've posted would belong in the data portion of your mod (whether directly in data.lua or a file required by it). But yeah, send me the code and I'll look and see why it's not working as expected.

User avatar
Phakx
Inserter
Inserter
Posts: 32
Joined: Sun Sep 07, 2014 8:57 pm
Contact:

Re: Recipe categories

Post by Phakx »

So if i create a control.lua and add the code inside of it it won't work?
I mean this could be the reason. I try this out and give you later response
Check out my "TrueBuildings" - Mod

User avatar
Phakx
Inserter
Inserter
Posts: 32
Joined: Sun Sep 07, 2014 8:57 pm
Contact:

Re: Recipe categories

Post by Phakx »

Okay. this is what i add in a new .lua file i called "builder":

Code: Select all

data:extend(
{
  {
    type = "assembling-machine",
    name = "MilitaryBuilder",
    icon = "__TrueBuildings__/graphics/icons/militarybuilder.png",
    flags = {"placeable-neutral", "placeable-player", "player-creation"},
    minable = {hardness = 0.2, mining_time = 0.5, result = "MilitaryBuilder"},
    max_health = 200,
    corpse = "big-remnants",
    dying_explosion = "huge-explosion",
    resistances =
    {
      {
        type = "fire",
        percent = 70
      }
    },
    collision_box = {{-1.4, -1.4}, {1.4, 1.4}},
    selection_box = {{-1.5, -1.5}, {1.5, 1.5}},
    fast_replaceable_group = "assembling-machine",
    animation =
      {
        priority = "extra-high",
        frame_width = 156,
        frame_height = 127,
        line_length = 10,
        shift = {1.00, -0.2},
        filename = "__TrueBuildings__/graphics/entity/builder/militarysheet.png",
        frame_count = 50,
        animation_speed = 0.5,
        run_mode = "forward-then-backward",
      },
    crafting_categories = {"military-crafting"},
    crafting_speed = 0.5,
    energy_source =
    {
      type = "electric",
      usage_priority = "secondary-input",
      emissions = 0.05 / 1.5
    },
    energy_usage = "90kW",
    ingredient_count = 2,
    open_sound = { filename = "__base__/sound/machine-open.ogg", volume = 0.85 },
    close_sound = { filename = "__base__/sound/machine-close.ogg", volume = 0.75 },
    working_sound =
    {
      sound = {
        {
          filename = "__base__/sound/assembling-machine-t1-1.ogg",
          volume = 0.8
        },
        {
          filename = "__base__/sound/assembling-machine-t1-2.ogg",
          volume = 0.8
        },
      },
      idle_sound = { filename = "__base__/sound/idle1.ogg", volume = 0.6 },
      apparent_volume = 1.5,
    }
  },
  {
    type = "recipe",
    name = "radar",
	category = "military-crafting",
    ingredients =
    {
      {"cabling", 10},
      {"iron-gear-wheel", 5},
	  {"iron-stick", 10},
      {"iron-plate", 20},
      {"stone-brick", 20},
    },
    result = "radar"
  }
})
for name, prototype in pairs(data.raw["assembling-machine"]) do -- remove this for loop if you only want your military builder to be able to make it.
  if name:find("assembling%-machine") then -- only for assembling-machine types with the text assembling-machine in their name
    table.insert(prototype.crafting_categories, "military-crafting")
  end
end
I load it via data.lua
But if i test it all it show is this:
Image

EDIT: oh and if i remove your for loop it gives me an error message :(
Check out my "TrueBuildings" - Mod

cartmen180
Filter Inserter
Filter Inserter
Posts: 358
Joined: Fri Jul 25, 2014 2:53 pm
Contact:

Re: Recipe categories

Post by cartmen180 »

you can only input 2 ingredients in your machine while your radar requires 5
set ingredient_count = 5 and it should work
Last edited by cartmen180 on Sun Oct 05, 2014 3:10 pm, edited 1 time in total.
Check out my mods

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: Recipe categories

Post by FreeER »

Phakx wrote:EDIT: oh and if i remove your for loop it gives me an error message :(
really? what's the error?
cartmen180 wrote:your ingredient count = 2 while your radar requires 5 different ingredients
This. I didn't even realize that Factorio considered that when calculating whether the entity should be shown or not.

User avatar
Phakx
Inserter
Inserter
Posts: 32
Joined: Sun Sep 07, 2014 8:57 pm
Contact:

Re: Recipe categories

Post by Phakx »

Oh i didn't think of this :(
my bad. Worked perfectly now.
Many many many thanks to the best support on this forum ;)
Check out my "TrueBuildings" - Mod

User avatar
Phakx
Inserter
Inserter
Posts: 32
Joined: Sun Sep 07, 2014 8:57 pm
Contact:

Re: Recipe categories

Post by Phakx »

FreeER this is the error message i got after i remove the upper line and the last end

Image
Check out my "TrueBuildings" - Mod

Post Reply

Return to “Modding help”