Sign in to follow this  
Foxrai

IsRecipeValid error - occurs since today?

Recommended Posts

Foxrai    12

Here is the error I encountered today. Note that YESTERDAY (!?) everything was working just fine. None of the files or codes have been changed. Just... suddenly an error came.

 

Seems to be about these in the modmain:

if not GLOBAL.TheNet:IsDedicated() then    local OldIsRecipeValid = GLOBAL.IsRecipeValid    local function IsRecipeValid(recipe)        return OldIsRecipeValid(recipe) and            ((GLOBAL.ThePlayer and GLOBAL.ThePlayer:HasTag(recipe.name.."_builder")) or not recipe.tagneeded)    end    GLOBAL.IsRecipeValid = IsRecipeValidend 

Error from the log:

 

[string "../mods/workshop-389385830/modmain.lua"]:75: variable 'IsRecipeValid' is not declared
LUA ERROR stack traceback:
 
In character I have tag of "something_builder". So the purpouse is to not let other people obtain this recipe (unless thet play the same character of course). 
 
So... Question is:
Why it just stopped working if it was working just fine?
How to fix it and how to avoid it in future? 

Share this post


Link to post
Share on other sites
Maris    231

Show line #75  :-)

 

Btw, try to change

local function IsRecipeValid(recipe)

​to

function IsRecipeValid(recipe)

​(remove "local")

Edited by Maris

Share this post


Link to post
Share on other sites

Sorry not quite sure, but I am in the same boat. The last DST patch killed a few mods, while others have not been effected.  I believe they moved some Global stuff around / cut some out.

 

 

Atm I am having problems with Item descriptions being stored in my items prefabs T_T. Its like my custom character name is no longer global to the rest of the mod, only valid in the modmain.

Share this post


Link to post
Share on other sites
Jjmarco    54

@Foxrai, It seems the original IsRecipeValid got moved in the last update. It's now in widgets/widgetutil.lua.

Try adding GLOBAL.require("widgets/widgetutil") in your modmain.

Share this post


Link to post
Share on other sites

I believe that did the trick.

 

Also recipes renamed the .tagneeded to .builder_tag

 

 

Edit: Hmm.... still getting an Hastag error tho. I think GLOBAL.ThePlayer:HasTag is the issue. Meh no idea

Edited by JadeKnightblazer

Share this post


Link to post
Share on other sites

calling 'HasTag' on bad self (string expected, got boolean)

 

 

Now i do add this line of code to my recipes...

local sortkey = -110000for k,v in pairs(recipes) do    sortkey = sortkey - 1    v.sortkey = sortkey    v.builder_tag = true	v.atlas = "images/inventoryimages/" .. v.name .. ".xml"end

But now with Recipe class... I don't people need the

if not GLOBAL.TheNet:IsDedicated() then    local OldIsRecipeValid = GLOBAL.IsRecipeValid	local function IsRecipeValid(recipe)        return OldIsRecipeValid(recipe) and            ((GLOBAL.ThePlayer and GLOBAL.ThePlayer:HasTag(recipe.name.."_builder")) or not recipe.builder_tag)    end    GLOBAL.IsRecipeValid = IsRecipeValidend

anymore because of this?

Recipe = Class(function(self, name, ingredients, tab, level, placer, min_spacing, nounlock, numtogive, builder_tag)    self.name          = name    self.placer        = placer    self.ingredients   = ingredients    self.product       = name    self.tab           = tab    self.atlas         = resolvefilepath("images/inventoryimages.xml")    self.image         = name .. ".tex"    self.sortkey       = num    self.level         = level or 0    self.level.ANCIENT = self.level.ANCIENT or 0    self.level.MAGIC   = self.level.MAGIC or 0    self.level.SCIENCE = self.level.SCIENCE or 0    self.placer        = placer    self.min_spacing   = min_spacing or 3.2    self.nounlock      = nounlock or false    self.numtogive     = numtogive or 1    self.builder_tag   = builder_tag or nil    num                = num + 1    AllRecipes[name]      = selfend)

Seems Recipes have gained the parameter to check the if the player has the needed tag?

 

Going to test it.

Edited by JadeKnightblazer

Share this post


Link to post
Share on other sites

Last Test: I am correct, with the New Recipe Parameter : builder_tag

 

You no longer need this hack

if not GLOBAL.TheNet:IsDedicated() then    local OldIsRecipeValid = GLOBAL.IsRecipeValid    local function IsRecipeValid(recipe)        return OldIsRecipeValid(recipe) and            ((GLOBAL.ThePlayer and GLOBAL.ThePlayer:HasTag(recipe.name.."_builder")) or not recipe.builder_tag)    end    GLOBAL.IsRecipeValid = IsRecipeValidend

Just have to make sure custom characters are given the same builder_tag in their character prefab.

Share this post


Link to post
Share on other sites
Jjmarco    54

@JadeKnightblazer, Indeed, you're right!

 

Overriding IsRecipeValid is no longer necessary. They probably added that in anticipation of the RoG characters they might add at some point.

 

Edit: Actually they are already using it for Wickerbottom's books.

Edited by Jjmarco

Share this post


Link to post
Share on other sites
Foxrai    12
It seems the original IsRecipeValid got moved in the last update. It's now in widgets/widgetutil.lua. Try adding GLOBAL.require("widgets/widgetutil") in your modmain.

 

Um... So I add it for example after this? 

local require = GLOBAL.requirelocal STRINGS = GLOBAL.STRINGSlocal Recipe = GLOBAL.Recipelocal RECIPETABS = GLOBAL.RECIPETABSlocal TECH = GLOBAL.TECHlocal resolvefilepath = GLOBAL.resolvefilepath

and on the end adding line: (?)

GLOBAL.require("widgets/widgetutil") 

 

and deleting at all this:

if not GLOBAL.TheNet:IsDedicated() then    local OldIsRecipeValid = GLOBAL.IsRecipeValid    local function IsRecipeValid(recipe)        return OldIsRecipeValid(recipe) and            ((GLOBAL.ThePlayer and GLOBAL.ThePlayer:HasTag(recipe.name.."_builder")) or not recipe.tagneeded)    end    GLOBAL.IsRecipeValid = IsRecipeValidend 

Or what else? 

Sorry guys I'm kinda clueless if it comes to coding :/

Edited by Foxrai

Share this post


Link to post
Share on other sites
Jjmarco    54

@Foxrai, Just delete all the lines that deal with IsRecipeValid. They're not needed anymore.

You don't even need to add require("widgets/widgetutil").

 

Then, assuming you're using the same code as rezecib, replace v.tagneeded = true with v.builder_tag = v.name.."_builder":

local sortkey = -9000for k,v in pairs(recipes) do    sortkey = sortkey - 1    v.sortkey = sortkey    v.builder_tag = v.name.."_builder"end

Alternatively, you could directly specify the tag in the Recipe definition:

Recipe(<name>, {<ingredients>}, <tab>, <level>, nil, nil, nil, nil, "<name>_builder")
Edited by Jjmarco

Share this post


Link to post
Share on other sites
rezecib    3157

Yup, confirming here, when they made Willow's lighter craftable they added a buildertag parameter to the Recipe(...) constructor. So that basically provides official support for what I was doing with the IsRecipeValid modification, so that's no longer necessary. What I'm doing in DST RoG Characters right now is just this:

	Recipe("spidereggsack", {Ingredient("silk", 12), Ingredient("spidergland", 6), Ingredient("papyrus", 6)}, RECIPETABS.TOWN, TECH.NONE, nil, nil, nil, nil, "spiderwhisperer"),	Recipe("wathgrithrhat", {Ingredient("goldnugget", 2), Ingredient("rocks", 2)}, RECIPETABS.WAR, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0}, nil, nil, nil, nil, "viking"),	Recipe("spear_wathgrithr", {Ingredient("twigs", 2), Ingredient("flint", 2), Ingredient("goldnugget", 2)}, RECIPETABS.WAR, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0}, nil, nil, nil, nil, "viking"),

With Wigfrid having the "viking" tag and Webber having the "spiderwhisperer" tag.

Share this post


Link to post
Share on other sites
Foxrai    12

 

@Foxrai, Just delete all the lines that deal with IsRecipeValid. They're not needed anymore.

You don't even need to add require("widgets/widgetutil").

 

Then, assuming you're using the same code as rezecib, replace v.tagneeded = true with v.builder_tag = v.name.."_builder":

local sortkey = -9000for k,v in pairs(recipes) do    sortkey = sortkey - 1    v.sortkey = sortkey    v.builder_tag = v.name.."_builder"end

Alternatively, you could directly specify the tag in the Recipe definition:

Recipe(<name>, {<ingredients>}, <tab>, <level>, nil, nil, nil, nil, "<name>_builder")

 

I went the shorter way  ;) Worked fine! Thank you guys! All FIXED with:

 

Recipe(<name>, {<ingredients>}, <tab>, <level>, nil, nil, nil, nil, "<name>_builder")

Edited by Foxrai

Share this post


Link to post
Share on other sites
Foxrai    12
Correct it is shorter and it allows which items you want to be private quite easily. However I would suggest using a .sortkey, for dedicated server support.
 

 

Sortkeys I'm using are similar to -998231 numbers. Because they have to be hmm.. unique, ye? So they don't argue with any other mod-sortkeys?

Share this post


Link to post
Share on other sites

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
Sign in to follow this