Dump all recipes from the game

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Vilsol
Burner Inserter
Burner Inserter
Posts: 6
Joined: Thu Aug 06, 2015 5:27 pm
Contact:

Dump all recipes from the game

Post by Vilsol »

I was wondering if there was a way to dump all recipes, technologies, etc, so that I could use them in an external tool.

Thanks in advance
User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Dump all recipes from the game

Post by prg »

Those are already stored in a convenient format in data/base/prototypes/.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
Vilsol
Burner Inserter
Burner Inserter
Posts: 6
Joined: Thu Aug 06, 2015 5:27 pm
Contact:

Re: Dump all recipes from the game

Post by Vilsol »

yes, but if I have tons of mods, means I have to go through so many folders, its insane, also, many mods use variables in their recipes, where extracting them would take quite some time
User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Dump all recipes from the game

Post by prg »

Iterate over game.forces.player.recipes/technologies and pull out the stuff you care for.

Code: Select all

/c local foo = "" for k, v in pairs(game.forces.player.recipes) do foo = foo .. "recipe "..k.." has "..tostring(#v.ingredients).." ingredients\n" end game.makefile("recepies", foo)
See https://forums.factorio.com/wiki/inde ... Lua/Recipe and https://forums.factorio.com/wiki/inde ... Technology for what keys to find in there, iterate over tables therein and format output to taste. The "recepies" file will be put into the script-output directory.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
User avatar
cpy
Filter Inserter
Filter Inserter
Posts: 839
Joined: Thu Jul 31, 2014 5:34 am
Contact:

Re: Dump all recipes from the game

Post by cpy »

Heh that's what i was looking for too! Saving just recipe names is good enough for me.
antropod
Manual Inserter
Manual Inserter
Posts: 3
Joined: Fri Sep 25, 2015 9:56 pm
Contact:

Re: Dump all recipes from the game

Post by antropod »

Hey guys, I made a lua script to dump all recipes to a json file.
Just copy and paste in game console, then check file named `recipes` in script-output directory.
It's not formatted though.

Code: Select all

/c
local out = ""

function write(...)
  local arg = {...}
  for i, v in ipairs(arg) do
    out = out .. tostring(v)
  end
end

function item_count(node)
  local count = 0
  for k, v in pairs(node) do
    count = count + 1
  end
  return count
end

function traverse_table(node)
  write("{")
  level = level + 1
  local i = 1
  local count = item_count(node)
  for k, v in pairs(node) do
    write("\"", tostring(k), "\": ")
    traverse(v)
    if i < count then
      write(",")
    end
    i = i + 1
  end
  write("}")
end

function traverse_array(node)
  local count = item_count(node)
  write("[")
  for k, v in ipairs(node) do
    traverse(v)
    if k < count then
      write(",")
    end
  end
  write("]")
end

function traverse(node)
  if type(node) == "table" then
    if type(next(node)) == "number" then
      traverse_array(node)
    else
      traverse_table(node)
    end
  elseif type(node) == "string" then
    write("\"", node, "\"")
  else
    write(node)
  end
end

function inspect_recipe(node)
  return {
    name=node.name,
    category=node.category,
    products=node.products,
    ingredients=node.ingredients,
    hidden=node.hidden,
    energy=node.energy,
    order=node.order
  }
end


function inspect_all(recipes)
  local r = {}
  for k, v in pairs(recipes) do
    r[k] = inspect_recipe(v)
  end
  traverse(r)
end

inspect_all(game.player.force.recipes)

game.makefile("recipes", out)
antropod
Manual Inserter
Manual Inserter
Posts: 3
Joined: Fri Sep 25, 2015 9:56 pm
Contact:

Re: Dump all recipes from the game

Post by antropod »

orzelek
Smart Inserter
Smart Inserter
Posts: 3924
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Dump all recipes from the game

Post by orzelek »

You can take a look here:
serpent

Would make part of your scripts much easier to do I think and it's available by default.
User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12889
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Re: Dump all recipes from the game

Post by ssilk »

Moved from general to gameplay help
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...
Post Reply

Return to “Gameplay Help”