data.raw["recipe"] does not exist

Place to get help with not working mods / modding interface.
pfg
Burner Inserter
Burner Inserter
Posts: 13
Joined: Wed Sep 21, 2016 9:57 pm
Contact:

data.raw["recipe"] does not exist

Post by pfg »

I'm working on a mod and it needs to get some recipes from the base game. It seems that doing

Code: Select all

data.raw["recipe"]
returns nil and the only thing in

Code: Select all

data.raw
is the one thing my mod managed to register before erroring.

data.raw:

Code: Select all

   0.697 Script @__modname__/api/filename.lua:4: {
  fluid = {
    ["fluidname"] = {
      base_color = {
        b = 0.1,
        g = 0.2,
        r = 0.8
      },
      default_temperature = 0,
      flow_color = {
        b = 0.1,
        g = 0.1,
        r = 0.7
      },
      flow_to_energy_ratio = 0.58999999999999995,
      heat_capacity = "0KJ",
      icon = "__modname__/graphics/icons/fluid/fluidicon.png",
      max_temperature = 100,
      name = "fluidname,
      order = "e[lubricant]",
      pressure_to_speed_ratio = 0.4,
      subgroup = "tool",
      type = "fluid"
    }
  }
}
File:

Code: Select all

string.split = require("api.split")

function functionName(s,name)
  log(serpent.block(data.raw, {comment=false, sparse=true}))
  if(type(s) == "string") then
    if(s == "default") then
      return data.raw["recipe"][name]["ingredients"]; -- Errors saying `attempt to index field 'recipe' (a nil value)`
    end
    items = string.split(s,",",false)
    for i, item in ipairs(items) do
      icn = string.split(item,":",false)
      items[i] = {icn[1], tonumber(icn[2])}
    end
    return items
  end
  return s
end

return functionName

Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: data.raw["recipe"] does not exist

Post by Nexela »

Post the whole code, or at least the whole code that adds the fluid.
pfg
Burner Inserter
Burner Inserter
Posts: 13
Joined: Wed Sep 21, 2016 9:57 pm
Contact:

Re: data.raw["recipe"] does not exist

Post by pfg »

Nexela wrote:Post the whole code, or at least the whole code that adds the fluid.

Code: Select all

parseColor = require("api.parse_color")

function addFluid(name,base_color,flow_color,icon)
  data:extend({
    {
      type = "fluid",
      name = name,
      default_temperature = 0,
      max_temperature = 0,
      heat_capacity = "0KJ",
      base_color = parseColor(base_color),
      flow_color = parseColor(flow_color),
      subgroup = "tool",
      max_temperature = 100,
      icon = icon,
      pressure_to_speed_ratio = 0.4,
      flow_to_energy_ratio = 0.59,
      order = "e[lubricant]",
    }
  })
end

return addFluid
Fluids added fine in 0.14
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: data.raw["recipe"] does not exist

Post by Nexela »

Somewhere before the fluid code then you must be doing data.raw = {} ?

You will have to package everything up so we can take a look
pfg
Burner Inserter
Burner Inserter
Posts: 13
Joined: Wed Sep 21, 2016 9:57 pm
Contact:

Re: data.raw["recipe"] does not exist

Post by pfg »

Nexela wrote:Somewhere before the fluid code then you must be doing data.raw = {} ?

You will have to package everything up so we can take a look

data.raw is used in the following places in the entire project. The project also worked in 0.14:

Code: Select all

      enabled = data.raw["recipe"][name]["enabled"],

  log(serpent.block(data.raw, {comment=false, sparse=true}))

      return data.raw["recipe"][name]["ingredients"];

--[[data.raw["lab"]["lab"]["inputs"] = {
--[[data.raw["lab"]["lab"]["inputs"] = {
data.raw["lab"]["lab"]["fluid_boxes"] = { -- (commented out)
Edit: https://www.dropbox.com/s/bof8w24nxgxo1 ... 2.zip?dl=0
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: data.raw["recipe"] does not exist

Post by Nexela »

settings.lua is a special file ran in the settings stage which is before the data stage, Simply rename this file (and where it is required from) to something else.
pfg
Burner Inserter
Burner Inserter
Posts: 13
Joined: Wed Sep 21, 2016 9:57 pm
Contact:

Re: data.raw["recipe"] does not exist

Post by pfg »

Nexela wrote:settings.lua is a special file ran in the settings stage which is before the data stage, Simply rename this file (and where it is required from) to something else.
Thanks that fixed it
Post Reply

Return to “Modding help”