data.raw["recipe"] does not exist
Posted: Sun Jan 28, 2018 6:03 am
I'm working on a mod and it needs to get some recipes from the base game. It seems that doing returns nil and the only thing in is the one thing my mod managed to register before erroring.
data.raw:
File:
Code: Select all
data.raw["recipe"]
Code: Select all
data.raw
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"
}
}
}
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