Jump to content

Recommended Posts

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 by LordMogar

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

 

 

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")

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...