Accessing data from control.lua

Place to get help with not working mods / modding interface.
Post Reply
sherlockholmes221b
Burner Inserter
Burner Inserter
Posts: 10
Joined: Tue Dec 31, 2019 6:02 pm
Contact:

Accessing data from control.lua

Post by sherlockholmes221b »

Hi, I work on mod with scenario. The main idea of the mod is creating a factory producing food and serving it. I have an entity "orderer", which should choose randomly a recipe, set it to itself and if it got what it wanted, choose next recipe and so on. The problem is, I can't access game data to randomly choose a recipe. Is there any way of getting recipes available for LuaRecipeCategory or LuaEntity?

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Accessing data from control.lua

Post by DaveMcW »

Recipe category:

Code: Select all

local category = "smelting"
local recipes = {}
for _, recipe in pairs(game.recipe_prototypes) do
  if recipe.category == category then
    table.insert(recipes, recipe.name)
  end
end
Entity:

Code: Select all

local entity = game.surfaces[1].find_entities_filtered{type="furnace", limit=1}[1]
local categories = entity.prototype.crafting_categories
local recipes = {}
for _, recipe in pairs(game.recipe_prototypes) do
  for category, _ in pairs(categories) do
    if recipe.category == category then
      table.insert(recipes, recipe.name)
    end
  end
end

Post Reply

Return to “Modding help”