LordMogar Posted May 6, 2015 Share Posted May 6, 2015 (edited) So, my item is meant to be crafted exclusively by one character. Upon loading the world, the game freezes up and crashes. I checked the log file and it printed this error which I haven't seen before. "attempt to concatenate field 'name' (a nil value)" What exactly does that mean? I'm not very experienced with programming, so if this is really obvious to anyone, then. Woops. Here's the code I've been working with. It is of course in the modmain file.if not GLOBAL.TheNet:IsDedicated() thenlocal OldIsRecipeValid = GLOBAL.IsRecipeValidlocal function IsRecipeValid(recipe)return OldIsRecipeValid(recipe) and((GLOBAL.ThePlayer and GLOBAL.ThePlayer:HasTag(recipe.name.."_builder")) or not recipe.tagneeded)-- Above line causing crash.endGLOBAL.IsRecipeValid = IsRecipeValidend local recipes = {Recipe("bear", {Ingredient("furtuft", 6),Ingredient("steelwool", 2), Ingredient("sewing_kit", 1)}, GLOBAL.RECIPETABS.DRESS, TECH.SCIENCE_TWO)} recipes[1].atlas = "images/inventoryimages/bear.xml" GLOBAL.STRINGS.RECIPE_DESC.BEAR = "A fuzzy stuffed replica of the Bearger."for k,v in pairs(recipes) dov.tagneeded = trueend Edited May 6, 2015 by LordMogar Link to comment https://forums.kleientertainment.com/forums/topic/53563-help-with-making-recipe-character-exclusive/ Share on other sites More sharing options...
Sheepolution Posted May 6, 2015 Share Posted May 6, 2015 Concatenate means to put together multiple strings. It says that the field name of recipe is nil (it has no value). Looking into recipe.lua we find the function IsRecipeValid and see that its parameter is recname. This means that when IsRecipeValid is called with the name of the recipe, not the recipe object. Looking further into original source, we can find this line: AllRecipes[name] = self So what you need to do is change your code to this:if not GLOBAL.TheNet:IsDedicated() thenlocal OldIsRecipeValid = GLOBAL.IsRecipeValidlocal function IsRecipeValid(recipe)return OldIsRecipeValid(recipe) and((GLOBAL.ThePlayer and GLOBAL.ThePlayer:HasTag(recipe.."_builder")) or not AllRecipes[recipe].tagneeded)-- Above line causing crash.endGLOBAL.IsRecipeValid = IsRecipeValidend local recipes = {Recipe("bear", {Ingredient("furtuft", 6),Ingredient("steelwool", 2), Ingredient("sewing_kit", 1)}, GLOBAL.RECIPETABS.DRESS, TECH.SCIENCE_TWO)} recipes[1].atlas = "images/inventoryimages/bear.xml" GLOBAL.STRINGS.RECIPE_DESC.BEAR = "A fuzzy stuffed replica of the Bearger."for k,v in pairs(recipes) dov.tagneeded = trueend Link to comment https://forums.kleientertainment.com/forums/topic/53563-help-with-making-recipe-character-exclusive/#findComment-634879 Share on other sites More sharing options...
LordMogar Posted May 6, 2015 Author Share Posted May 6, 2015 Changed my code to that, now the log's saying "attempt to index global 'AllRecipes' (a nil value)". That must mean I'm not referencing something correctly, right? I'm probably missing a line somewhere. Link to comment https://forums.kleientertainment.com/forums/topic/53563-help-with-making-recipe-character-exclusive/#findComment-634880 Share on other sites More sharing options...
Sheepolution Posted May 6, 2015 Share Posted May 6, 2015 Maybe you need to put GLOBAL. in front of AllRecipes[recipe].tagneeded? Doesn't make a lot of sense to me why you would need to do that, but else I wouldn't know. Link to comment https://forums.kleientertainment.com/forums/topic/53563-help-with-making-recipe-character-exclusive/#findComment-634882 Share on other sites More sharing options...
LordMogar Posted May 6, 2015 Author Share Posted May 6, 2015 Ah, that did the trick. It's working just fine now. Thanks for the help! Link to comment https://forums.kleientertainment.com/forums/topic/53563-help-with-making-recipe-character-exclusive/#findComment-634883 Share on other sites More sharing options...
DarkXero Posted May 6, 2015 Share Posted May 6, 2015 There's AddRecipe, in modutil.lua, for the mod environment.It takes all the parameters from recipe, and returns you the recipe, if you want to modify the sortkey or something.local myrecipe = AddRecipe("bear", -- name{GLOBAL.Ingredient("furtuft", 6), GLOBAL.Ingredient("steelwool", 2), GLOBAL.Ingredient("sewing_kit", 1)}, -- ingredientsGLOBAL.RECIPETABS.DRESS, -- tabGLOBAL.TECH.SCIENCE_TWO, -- levelnil, nil, nil, nil, -- placer, min_spacing, nounlock, numtogive"teddymaker", -- builder_tag"images/inventoryimages/bear.xml", "bear.tex") -- atlas, imageGLOBAL.STRINGS.RECIPE_DESC.BEAR = "A fuzzy stuffed replica of the Bearger."-- then in your character you do inst:AddTag("teddymaker") Link to comment https://forums.kleientertainment.com/forums/topic/53563-help-with-making-recipe-character-exclusive/#findComment-634964 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now