Page 1 of 1

[0.18.x] game.get_filtered_recipe_prototypes

Posted: Sun Jun 14, 2020 1:16 am
by osldgoth
Hello all, does anyone have examples on how, or know how, to filter recipe prototypes? I can't get the results I want.

Code: Select all

local filteredRecipies = game.get_filtered_recipe_prototypes{{
      filter = "has-ingredient-item",
      elem_filters = {{filter = "name", name = inventoryContent, 
                       elem_filters = {{filter = "category", category = "smelting",
                       mode = "and"}}
      }}}}

Re: [0.18.x] game.get_filtered_recipe_prototypes

Posted: Mon Jun 15, 2020 11:08 pm
by osldgoth
btw this does work but it requires a loop with the if statement to narrow down the results further (and yes I realize this will only return the first one it comes across and not all if there is more than one to filter, which is fine in my case for now)

Code: Select all

  local inventoryContent = next(entity.get_inventory(defines.inventory.furnace_source).get_contents())
  if not inventoryContent then return nil end
  local filteredRecipies = game.get_filtered_recipe_prototypes{{filter = "has-ingredient-item", elem_filters = {{filter = "name", name = inventoryContent}}}}
  for k,v in pairs(filteredRecipies) do
    if v.category == "smelting" then
      return v
    end
  end