Page 1 of 1

data.raw["recipe"] does not exist

Posted: Sun Jan 28, 2018 6:03 am
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


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

Posted: Sun Jan 28, 2018 6:48 am
by Nexela
Post the whole code, or at least the whole code that adds the fluid.

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

Posted: Sun Jan 28, 2018 6:52 am
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

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

Posted: Sun Jan 28, 2018 6:57 am
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

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

Posted: Sun Jan 28, 2018 7:03 am
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

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

Posted: Sun Jan 28, 2018 7:34 am
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.

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

Posted: Sun Jan 28, 2018 7:49 am
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