Page 1 of 1
Prototype name (recipe)
Posted: Mon Jul 09, 2018 10:48 pm
by hedikin
okay so i been trying to figure this one out all day and im no way closer to figuring this one out.
trying to make a small mod that alters a few recipes in a mod, so it would add another top layer of complexity and figured i might as well try to learn some coding in the process
im using a data-updates.lua file
my error:
Error loading mods
Failed to load mods: Prototype name (recipe) does not match the key name (1)
mods to be disabled:
mine
Re: Prototype name (recipe)
Posted: Tue Jul 10, 2018 2:05 am
by eradicator
First thing you need to learn about coding is how to ask the right questions. Because that one has way too few details. For starters try posting the problematic bit of code. No worries, everyone bites here.
Re: Prototype name (recipe)
Posted: Tue Jul 10, 2018 9:53 pm
by hedikin
eradicator wrote:First thing you need to learn about coding is how to ask the right questions. Because that one has way too few details. For starters try posting the problematic bit of code. No worries, everyone bites here.
okay ill look forward to more bitemarks then
data-updates.lua:
Code: Select all
if data.raw["recipe"]["old_recipe"] then
data.raw["recipe"]["old_recipe"] = nil
local new_recipe = {
type = "recipe",
name = "new_crafting_recipe", -- name of the item in recipes
energy_required = 60.0, -- time required to make the recipe
enabled = "true",
ingredients = { -- which items is needeed to make it
{ type = "item", name = "crafting_item_needed", amount=1},
},
results = { -- what the machine spits out
{ type = "item", name = "old_recipe_item", amount= 1},
{ type = "item", name = "old_recipe_item2, amount = 1, probability=0.25}, -- gives 25% chance instead of 1 per craft -- altered recipe
},
subgroup = "fuel", category = "fuel",
icon_size = 32, icon = "icon_location",
}
table.insert(data.raw["recipe"], new_recipe)
end
Re: Prototype name (recipe)
Posted: Tue Jul 10, 2018 9:56 pm
by eradicator
Why the secret recipe naming ;)?
data.raw isn't a normal table. It probably doesn't like your = nil'ing and table.insert() ing.
If you want to change an existing recipe just edit it's table in-place.
If you want to add a new recipe use data:extend{recipe}.
Re: Prototype name (recipe)
Posted: Tue Jul 10, 2018 10:06 pm
by hedikin
the reason for the "secrets" is because i havnt gotten permission from the original mod maker to alter his / her stuff. and this isnt a mod im going to be distributing, as its mostly for my own 'humour* if you will. so its out of respect tbh
now for your suggestion, just so i understand you correctly.
if data:extend["recipe"]["old_recipe"] then
etc etc
i got another file in prototypes called "recipes" that i have written the "new" recipes in, but the old ones is still active. thats why i was trying to just insert the new recipe instead. when i use
data.raw["recipe"][old_recipe].hidden = true
it will say my mod doesnt work.
Re: Prototype name (recipe)
Posted: Wed Jul 11, 2018 8:55 am
by bobingabout
hedikin wrote:if data:extend["recipe"]["old_recipe"] then
that won';t work, data:extend is purely for adding new data, use it instead of the insert.
data:extend{Full recipe table here}
EG
data:extend{
{
name = "my_recipe",
type = "recipe",
etc...
}
}
for your if check, use
if data.raw.recipe["my_recipe"] then
so it's the table.insert(data.raw["recipe"], new_recipe) line that would become data:extend{new_recipe}
Re: Prototype name (recipe)
Posted: Wed Jul 11, 2018 9:45 am
by eradicator
data.raw.recipe["old_recipe"].hidden = true looks fine though. Maybe you forgot the quotes?
You can shorten it a bit, but editing a recipe works like this:
Code: Select all
local old = data.raw.recipe["old_recipe_name"] --don't forget the quotes
old.hidden = true
old.energy_required = 60
old.ingredients = {}
--edited in place, no use of data:extend required
You can change everything except the name. If you change the name it's a new recipe and you need to use data:extend
Code: Select all
local new = util.table.deepcopy(data.raw.recipe["old_recipe_name"]) --copy of old
new.hidden = true
new.energy_required = 60
new.ingredients = {}
data:extend{new}
Re: Prototype name (recipe)
Posted: Fri Jul 13, 2018 7:55 pm
by hedikin
thanks ill try it out