Prototype name (recipe)

Place to get help with not working mods / modding interface.
hedikin
Burner Inserter
Burner Inserter
Posts: 16
Joined: Tue Mar 14, 2017 7:04 pm
Contact:

Prototype name (recipe)

Post 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
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Prototype name (recipe)

Post 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.
hedikin
Burner Inserter
Burner Inserter
Posts: 16
Joined: Tue Mar 14, 2017 7:04 pm
Contact:

Re: Prototype name (recipe)

Post 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


User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Prototype name (recipe)

Post 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}.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
hedikin
Burner Inserter
Burner Inserter
Posts: 16
Joined: Tue Mar 14, 2017 7:04 pm
Contact:

Re: Prototype name (recipe)

Post 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.
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Prototype name (recipe)

Post 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}
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Prototype name (recipe)

Post 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}
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
hedikin
Burner Inserter
Burner Inserter
Posts: 16
Joined: Tue Mar 14, 2017 7:04 pm
Contact:

Re: Prototype name (recipe)

Post by hedikin »

thanks ill try it out
Post Reply

Return to “Modding help”