I have tried to make a function that set some default values for some recipes, but it doesn't work. My guess is im doing something wrong, or it's something that cant be done the way i think.
Hope someone in here can help me solve the problem, if there is a way to do it.
my function:
function recValues(recipename)
recipe[recipename].icon = "__MyMod__/graphics/icon/recycling-progress.png"
recipe[recipename].hidden = "true"
recipe[recipename].category = "smeltning",
recipe[recipename].energy_required = 5,
end
The recipe:
{
type = "recipe",
name = "rec-iron-chest",
ingredients = {{"iron-chest", 1}},
results =
{{"iron-plate", 4}},
recValues("rec-iron-chest"),
},
The idea is to make a function that fill in the spots that won't change for all the recipes, im gonna make, spare a lot of lines of code.
recipe values
- ArderBlackard
- Long Handed Inserter
- Posts: 74
- Joined: Thu May 05, 2016 12:41 pm
- Contact:
Re: recipe values
Actually your function returns nothing so it's call results to 'nil' value. As a consequence you are inserting 'nil' value into the table which is the same as not inserting at all.
You may consider using the code like this:
As a result we create a table (as a parameter of the recValues function inside the data:extend call), fill it with some unique data, then pass it inside the recValues function where it receives the common values and then is returned and added to the data:extend parameter table.
Also Lua allows you to omit method call parentheses if there is only one parameter and it is a string or a table, so you can remove them from the recValues call to make it a bit clearer:
You may consider using the code like this:
Code: Select all
function recValues( prototype )
prototype.icon = "__MyMod__/graphics/icon/recycling-progress.png"
prototype.hidden = "true"
prototype.category = "smelting"
prototype.energy_required = 5
return prototype
end
data:extend{
recValues( {
type = "recipe",
name = "rec-iron-chest",
ingredients = {{"iron-chest", 1}},
results = {{"iron-plate", 4}},
} ),
}
Also Lua allows you to omit method call parentheses if there is only one parameter and it is a string or a table, so you can remove them from the recValues call to make it a bit clearer:
Code: Select all
data:extend{
recValues {
type = "recipe",
name = "rec-iron-chest",
ingredients = {{"iron-chest", 1}},
results = {{"iron-plate", 4}},
},
recValues {
type = "recipe",
name = "rec-iron-chest-1",
ingredients = {{"iron-chest", 2}},
results = {{"iron-plate", 5}},
},
}
Gib dich hin bis du Glück bist
- bobingabout
- Smart Inserter
- Posts: 7352
- Joined: Fri May 09, 2014 1:01 pm
- Contact:
Re: recipe values
I think you want to be using...
data.raw.recipe[recipename]
data.raw.recipe[recipename]
- ArderBlackard
- Long Handed Inserter
- Posts: 74
- Joined: Thu May 05, 2016 12:41 pm
- Contact:
Re: recipe values
Anyway in the provided code the function is called from the place where the recipe is not yet added to the data.raw table.bobingabout wrote:I think you want to be using...
data.raw.recipe[recipename]
Gib dich hin bis du Glück bist
Re: recipe values
ArderBlackard, the code you made, worked out perfect, thank you
- ArderBlackard
- Long Handed Inserter
- Posts: 74
- Joined: Thu May 05, 2016 12:41 pm
- Contact: