Accessing data from control.lua
-
- Burner Inserter
- Posts: 10
- Joined: Tue Dec 31, 2019 6:02 pm
- Contact:
Accessing data from control.lua
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?
Re: Accessing data from control.lua
Recipe category:
Entity:
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
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