Jump to content

Variable 'GetRecipe' is not declared


Recommended Posts

I'm making a mod, where a prototyper spawns somewhere in its own setpiece. It should grant new recipes in a new tab when the player is nearby.

I got setpiece and new tab working, but I don't know how to make it so the new recipe is unlocked only when I'm near the prototyper.

 

From modmain.lua:

PrefabFiles = {"gabenstatue","steampillar","festive_spike","festive_hambat","festive_batbat","festive_spear","hl3confirmed","tf2crate",}Assets = {Asset("ATLAS", "images/hud/gaben.xml" ),Asset("ATLAS", "images/inventoryimages/tf2crate.xml" ),Asset("IMAGE", "images/inventoryimages/tf2crate.tex" ),}local require = GLOBAL.requirelocal Builder = require "components/builder"local Recipe = GLOBAL.Recipelocal RECIPETABS = GLOBAL.RECIPETABSlocal STRINGS = GLOBAL.STRINGSlocal TECH = GLOBAL.TECHgabentab = AddRecipeTab("Gaben", 979, "images/hud/gaben.xml", "gaben.tex", nil)GLOBAL.TECH.NONE.GABENCRAFTER = 0for k,v in pairs(GLOBAL.TUNING.PROTOTYPER_TREES) do    GLOBAL.TUNING.PROTOTYPER_TREES[k].GABENCRAFTER = 0end--We define what a "GABENCRAFTER" prototyping machine grants us access to:GLOBAL.TUNING.PROTOTYPER_TREES.GABENCRAFTER = {SCIENCE = 0, MAGIC = 0, ANCIENT = 0, GABENCRAFTER = 1} AddRecipe("tf2crate", {Ingredient("boards",3),Ingredient("goldnugget",3)}, gabentab, {GABENCRAFTER = 1}, nil, -- placernil, -- min_spacingnil, -- nounlocknil, -- numtogivenil, -- builder_tag"images/inventoryimages/tf2crate.xml", -- atlas"tf2crate.tex") --)local function enteringgabenzone(doer)endlocal function leavinggabenzone(doer)    if doer and doer.components.builder then        doer.components.builder.accessible_tech_trees = GLOBAL.TECH.NONE    endendfunction gabenprototyper(inst)    inst:AddTag("prototyper")    inst:AddComponent("prototyper")        inst.components.prototyper.trees = GLOBAL.TUNING.PROTOTYPER_TREES.GABENCRAFTER        inst.components.prototyper.onturnoff = leavinggabenzone        inst.components.prototyper.onturnon = enteringgabenzoneendAddPrefabPostInit("gabenstatue", gabenprototyper)-----overwrite builder knowsrecipe to not ignore new tech tree------function builderpostinit(inst)local oldKnowsRecipe = inst.KnowsRecipeinst.KnowsRecipe = function(self, recname)local xrecipe = GLOBAL.GetRecipe(recname)if oldKnowsRecipe(self, recname) and not self.freebuildmode thenif xrecipe and xrecipe.level.GABENCRAFTER and xrecipe.level.GABENCRAFTER > 0 thenreturn falseelsereturn trueendendreturn oldKnowsRecipe(self, recname)endendAddComponentPostInit("builder", builderpostinit)

I looked into "Summons" mod and tried to replicate what was done, but... Well it doesn't work in DST.

 

Without "KnowsRecipe" Postinit player has unlocked the recipe and the tab right away.

 

Game crashed just after I pick a character (I guess it's because the crafting menu has to load, and there is an error, but GetRecipe is apparently not declared. But it is declared, so either I made a mistake somewhere or DST handles these things in a different way). Crash log:

[00:01:03]: [string "../mods/0GABEN/modmain.lua"]:72: variable 'GetRecipe' is not declaredLUA ERROR stack traceback:    =[C]:-1 in (global) error (C) <-1--1>    scripts/strict.lua:23 in () ? (Lua) <21-26>    ../mods/0GABEN/modmain.lua:72 in () ? (Lua) <71-81>    =(tail call):-1 in ()  (tail) <-1--1>    scripts/widgets/crafting.lua:172 in (method) UpdateRecipes (Lua) <163-218>    scripts/widgets/crafting.lua:47 in (field) _ctor (Lua) <13-48>    scripts/widgets/controllercrafting.lua:19 in (field) _ctor (Lua) <18-52>    scripts/class.lua:181 in (upvalue) ControllerCrafting (Lua) <171-184>    scripts/widgets/crafttabs.lua:64 in (field) _ctor (Lua) <46-205>    scripts/class.lua:181 in (upvalue) CraftTabs (Lua) <171-184>    scripts/widgets/controls.lua:136 in (field) _ctor (Lua) <30-151>    scripts/class.lua:181 in (upvalue) Controls (Lua) <171-184>    scripts/screens/playerhud.lua:363 in (method) SetMainCharacter (Lua) <357-389>    scripts/prefabs/player_common.lua:331 in (upvalue) ActivateHUD (Lua) <327-332>    scripts/prefabs/player_common.lua:536 in (local) fn (Lua) <511-547>    scripts/entityscript.lua:962 in (method) PushEvent (Lua) <956-979>    scripts/mainfunctions.lua:295 in () ? (Lua) <292-297>    =[C]:-1 in (method) SendSpawnRequestToServer (C) <-1--1>    scripts/mainfunctions.lua:1247 in (local) cb (Lua) <1245-1248>    scripts/frontend.lua:531 in (method) DoFadingUpdate (Lua) <506-535>    scripts/frontend.lua:583 in (method) Update (Lua) <543-696>    scripts/update.lua:94 in () ? (Lua) <39-127>

Any help would be appreciated.

Edited by PanAzej
Link to comment
Share on other sites

PrefabFiles =  { "gabenstatue", "steampillar", "festive_spike", "festive_hambat", "festive_batbat", "festive_spear", "hl3confirmed", "tf2crate", }

 

 

We'll see the end of the world before the end of developement. Yes, I purposely didn't specifiy what developement.

Link to comment
Share on other sites

 

 

GetRecipe do not exists for DST. You should use the table AllRecipes instead.

Thank you! 

 

So here's what I got so far:

PrefabFiles = {"gabenstatue","steampillar","festive_spike","festive_hambat","festive_batbat","festive_spear","hl3confirmed","tf2crate",}Assets = {Asset("ATLAS", "images/hud/gaben.xml" ),Asset("ATLAS", "images/inventoryimages/tf2crate.xml" ),Asset("IMAGE", "images/inventoryimages/tf2crate.tex" ),}local require = GLOBAL.requirelocal Builder = require "components/builder"local Recipe = GLOBAL.Recipelocal RECIPETABS = GLOBAL.RECIPETABSlocal STRINGS = GLOBAL.STRINGSlocal TECH = GLOBAL.TECHlocal AllRecipes = GLOBAL.AllRecipes gabentab = AddRecipeTab("Gaben", 979, "images/hud/gaben.xml", "gaben.tex", nil) GLOBAL.TECH.NONE.GABENCRAFTER = 0for k,v in pairs(GLOBAL.TUNING.PROTOTYPER_TREES) do    GLOBAL.TUNING.PROTOTYPER_TREES[k].GABENCRAFTER = 0end--We define what a "GABENCRAFTER" prototyping machine grants us access to:GLOBAL.TUNING.PROTOTYPER_TREES.GABENCRAFTER = {SCIENCE = 0, MAGIC = 0, ANCIENT = 0, GABENCRAFTER = 1}  AddRecipe("tf2crate", {Ingredient("boards",3),Ingredient("goldnugget",3)}, gabentab, {GABENCRAFTER = 1}, nil, -- placernil, -- min_spacingnil, -- nounlocknil, -- numtogivenil, -- builder_tag"images/inventoryimages/tf2crate.xml", -- atlas"tf2crate.tex") --)local function enteringgabenzone(doer)	end local function leavinggabenzone(doer)    if GLOBAL.ThePlayer then -- will checking "ThePlayer" work properly? Not sure        GLOBAL.ThePlayer.components.builder.accessible_tech_trees = GLOBAL.TECH.NONE    end end function gabenprototyper(inst)    inst:AddTag("prototyper")    inst:AddComponent("prototyper")        inst.components.prototyper.trees = GLOBAL.TUNING.PROTOTYPER_TREES.GABENCRAFTER        inst.components.prototyper.onturnoff = leavinggabenzone        inst.components.prototyper.onturnon = enteringgabenzoneendAddPrefabPostInit("gabenstatue", gabenprototyper)-----overwrite builder knowsrecipe to not ignore new tech tree------function builderpostinit(inst)	local oldKnowsRecipe = inst.KnowsRecipe	inst.KnowsRecipe = function(self, recname)		if oldKnowsRecipe(self, recname) and not self.freebuildmode then			if AllRecipes[recname] and AllRecipes[recname].level.GABENCRAFTER and AllRecipes[recname].level.GABENCRAFTER > 0 then				return false			else				return true			end					end		return oldKnowsRecipe(self, recname)	endendAddComponentPostInit("builder", builderpostinit)

1. "leavinggabenzone" - I'd need to check the player leaving the prototyper's area. Not too sure if 'ThePlayer' will work with multiple players though, and 'doer' either doesn't refer to the player or is something completely different I don't know about; calling it 'doers[doer]' didn't change anything too...

 

2. Another big problem is that prototyper grants access to a new recipetab to the player, but when I'm leaving its 'prototype radius' recipe is no longer usable but recipetab icon is still visible and clickable.

But! When picking up an item/moving around something in my inventory - it disappears.

I guess it's because widget gets updated after we use our inventory or something? No idea how to fix that.

Tab should disappear right away as we move out of prototyper's area.

Even if we know recipes (basically how ancient_altar does it, but... yeah. No idea how to do that. But even if this isn't possible to do, as long as tab icon acts properly it's fine).

 

I'm no good coder, but still trying to get this to work... I'm getting pretty stumped on this one, I gotta say.

Any help would be appreciated!

Edited by PanAzej
Link to comment
Share on other sites

So I never did a prototyper before but I don't think that the way you're doing it is right.

 

First

if GLOBAL.ThePlayer then   dostuffsend

is not doing what you want it to do.

In DST, ThePlayer refers to the host, always or nothing if it's a dedicated server. So this just checks if the host exists, which is obviously not what you want to do.

 

As far as I saw, from commentary of Klei themselves in the constant.lua where they define the tech levels, they put MAGIC_ONE = 2, with the comment that it starts at 2 to not be spoiled from the beginning.

So a level of something (science, magic, ancient, myownfancytechlevel, ...) equal to 1 means that it will appear on the craft bar right from the beginning. You just need to put your reciepes to require at least a level 2 in GABENTECH (or however you called it), so it's not appearing when not standing next to a prototyper which grants at least 2 GABENTECH.

Then everything you did to check the proximity and everything is useless.

 

At least that's my interpretation of what I saw so far.

Edited by ZupaleX
Link to comment
Share on other sites

Thank you for the response!

So I never did a prototyper before but I don't think that the way you're doing it is right.

 

First

if GLOBAL.ThePlayer then   dostuffsend

is not doing what you want it to do.

In DST, ThePlayer refers to the host, always or nothing if it's a dedicated server. So this just checks if the host exists, which is obviously not what you want to do.

 

As far as I saw, from commentary of Klei themselves in the constant.lua where they define the tech levels, they put MAGIC_ONE = 2, with the comment that it starts at 2 to not be spoiled from the beginning.

So a level of something (science, magic, ancient, myownfancytechlevel, ...) equal to 1 means that it will appear on the craft bar right from the beginning. You just need to put your reciepes to require at least a level 2 in GABENTECH (or however you called it), so it's not appearing when not standing next to a prototyper which grants at least 2 GABENTECH.

Then everything you did to check the proximity and everything is useless.

 

At least that's my interpretation of what I saw so far.

Setting GABENCRAFTER to 2 crashed the game after moving away from the prototyper and clicking on its recipetab icon (I guess it was because the game freaked out, since it had to generate a new, bigger background for crafttab icons, because it unloaded the tab completely? not completely sure, though)

 

Being how it is at the moment doesn't show "gabentab" at the start, just after we get close to the prototyper. I don't know how to check for the "prototyper-area leaving player", so I used ThePlayer to test it further anyways. 

 

Another problem is this, and I have no idea how to fix it (image below)

I want the menu to update instantly as we leave the prototyper. But it updates only after we iterate with inventory.

problum_by_pokekoks-d9kiwwz.jpg

Edited by PanAzej
Link to comment
Share on other sites

I made a custom crafting tab which doesn't show up when not next to at least a science machine and it doesn't crash the game when moving away from the machine. Could you post the crash log and your complete mod because I think the issue is in some of the functions you put which are not necessary.

Link to comment
Share on other sites

Huh, seems that I have screwed something up, because it didn't crash this time.

But the tab is always usable with "ThePlayer" part disabled. After we leave prototyper. And it acts as if we're learning a new recipe everytime we have ingredients.

 

I changed the GABENCRAFTER to 2, and commented out 'ThePlayer's. Download link (since I'm not permitted to attach my file for some reason):

https://drive.google.com/file/d/0B5Qj-AlmLzq-T1ZERGY0VmcwM2c/view?usp=sharing

 

(mod is still in development so many things have unfinished things, like some items sharing the same icon and stuff)

Edited by PanAzej
Link to comment
Share on other sites

Why do you add a PrefabPostInit to a prefab you created yourself in this very mod? (line 57)

 

I advise you to look at the scienceprototyper.lua as a template for your gabenstatue.lua

 

EDIT: I'm not convinced by your builder postinit also. I'll check it a bit closer.

EDIT2: Indeed, look a bit a the builder.lua component you will see you're missing some stuffs to define a new tech tree. Try to follow how the science is made for instance and apply it to your gaben.

Edited by ZupaleX
Link to comment
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
 Share

×
×
  • Create New...