[0.18.x] game.get_filtered_recipe_prototypes

Place to get help with not working mods / modding interface.
osldgoth
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Thu Feb 26, 2015 3:52 am
Contact:

[0.18.x] game.get_filtered_recipe_prototypes

Post 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"}}
      }}}}
osldgoth
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Thu Feb 26, 2015 3:52 am
Contact:

Re: [0.18.x] game.get_filtered_recipe_prototypes

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

Return to “Modding help”