MidrealmDM Posted October 2, 2016 Share Posted October 2, 2016 (edited) I am trying to allow juicy berries to be dried on the drying rack... I've already got the animation worked out for when the berries are hanging, But I need to insert these lines into the prefab for "berries_juicy" inst:AddComponent("dryable") inst.components.dryable:SetProduct("raisins") inst.components.dryable:SetDryTime(TUNING.DRY_FAST) I've tried various methods, but keep getting errors Any advice? Edited October 2, 2016 by MidrealmDM Issue Resolved Link to comment Share on other sites More sharing options...
Serpens Posted October 2, 2016 Share Posted October 2, 2016 Did you tried putting in modmain: AddPrefabPostInit("berries_juicy",function(inst) inst:AddComponent("dryable") inst.components.dryable:SetProduct("raisins") inst.components.dryable:SetDryTime(TUNING.DRY_FAST) end) if you already tried this, what is the error you get? Link to comment Share on other sites More sharing options...
MidrealmDM Posted October 2, 2016 Author Share Posted October 2, 2016 4 hours ago, Serpens said: Did you tried putting in modmain: AddPrefabPostInit("berries_juicy",function(inst) inst:AddComponent("dryable") inst.components.dryable:SetProduct("raisins") inst.components.dryable:SetDryTime(TUNING.DRY_FAST) end) if you already tried this, what is the error you get? @Serpens Yep tried that - sort of I was getting "unexpected character after the ',' " error because I had commas at the end of the lines tried again, without the commas and it worked. _Waiter 101 Together_ updated to version 4.22 on Steam Link to comment Share on other sites More sharing options...
Serpens Posted October 2, 2016 Share Posted October 2, 2016 (edited) On 2.10.2016 at 11:11 PM, MidrealmDM said: @Serpens Yep tried that - sort of I was getting "unexpected character after the ',' " error because I had commas at the end of the lines tried again, without the commas and it worked. _Waiter 101 Together_ updated to version 4.22 on Steam okay omg, that are alot of changes O.ô I always used my own version of your mod, cause of the incompatibilty to Craft Pot mod and because of too many new food tags. But now you fixed the incompatibilty and gave ivanx some cool images for the new tags, that's great But there are still some things I would improve: 1) In your script is three times "local require = .." You only need it once at the top of your script, same cooking and other things you defined more than once outside of a function. (won't cause problems, but it looks better in code) 2) you wrote "_G = GLOBAL" but it should be "local _G = GLOBAL", same for TUNING. (might cause problems with other mods, cause you define your variable for all mods without the local, I think) 3) In your meatrack modding, why did you leave out the "POPULATING check that is in the original function? I'm sure there is a good reason for this check, so you should add it, of course with GLOBAL. in fornt of it. (might cause crash if you do not add it) Other suggestions: 4) Please add the original SurfnTurf. Why did you replaced it? When playing shipwrecked I doubt you add it at all, since it would have the same animation as the original surfnturf. And wehn not playing SW it would be great to have the original surfnturf. The original is great because it is one of very few recipes that gives good sanity. 5) Some recipes like fruit_truffle or cheeselog have "and diary and not fat". Without other mods this means only goatmilk is possible. I also told you about this, but you said there could be also beefalo milk by another mod. Okay. But how about replacing this check by "and rawmilk" ? This would be the same, but better understandable when using Craft Pot mod. 6) These recipes I mentioned in 5): Goatmilk is very hard to gather. And none of your recipes is worth it to use goatmilk for it. That's why I would sugget to increase sanity value of those to ~ 50. 7) Maybe you could increase perishtime of mushroom medley to 3 or 6 days ? One day is quite extreme I think =/ Edited October 4, 2016 by Serpens Link to comment Share on other sites More sharing options...
Maris Posted October 4, 2016 Share Posted October 4, 2016 Actually it's not easy because item will be invisible on drying rack. But there is code example in Wanda mod (ready for copy&paste). Also you need some additional animations (you can use existing game art but you should create new animation files). Link to comment Share on other sites More sharing options...
blubuild Posted October 9, 2016 Share Posted October 9, 2016 On 10/3/2016 at 1:08 AM, Serpens said: 2) you wrote "_G = GLOBAL" but it should be "local _G = GLOBAL", same for TUNING. (might cause problems with other mods, cause you define your variable for all mods without the local, I think) No, each mod runs in its own separate environment, and in Lua creating a new global var (i.e. using a var name anywhere without first writing "local varname") adds it to the current environment (which is really just a table stored (referenced) in a global var*, like everything else in Lua: everything that isn't a plain value or a function or a userdata is a table). In Lua the current environment is stored in a global var called _G. In a DST mod environment (which is custom-made and more sparse than a standard Lua environment**), Klei set it up so the current environment is stored in a var called env instead, and the game's main environment ("the global environment") is stored in a var called GLOBAL. I think it's all completely identical in DS (singleplayer), as well. *: Yes, this global var is itself stored in the environment table as well, so in a standard Lua environment _G._G equals _G (as does _G._G._G._G...), and in a DST mod env.env == env. So accessing a global var with myvarname is actually kind of a shorthand for env.myvarname - which itself is a shorthand for env["myvarname"], by the way. Tidbit: this means that from a mod environment, GLOBAL._G == GLOBAL. So, each mod has its own sets of global vars, and a mod can only access or mess with another mod's global vars by specifically finding a reference to the other mod's environment table, and using it. Or using the Lua debug library, maybe. Yeah... I tried to be really informative, but it might have ended up confusing... so maybe not that good of an explanation to whoever doesn't know some of it already in the end. You can also learn the same here: https://www.lua.org/pil/1.2.html, https://www.lua.org/pil/14.html and by reading the Klei mods.lua file (specifically the CreateEnvironment function / line 225 onwards). **: A simple list for reference, this is everything that is available in a DST mod environment (this one is different from in singleplayer DS, naturally): Spoiler directly available in mod environment: lua pairs ipairs print math table type string tostring game Class TUNING CHARACTERLIST Prefab Asset Ingredient cookerrecipes --the mod's recipes mod functions GetModConfigData AddLevelPreInit AddLevelPreInitAny, AddTaskSetPreInit AddTaskSetPreInitAny AddTaskPreInit AddRoomPreInit AddLocation AddLevel AddTaskSet AddTask AddRoom AddStartLocation AddGamePostInit AddSimPostInit AddGlobalClassPostConstruct AddClassPostConstruct -- modmain only (not in worldgen): AddPrefabPostInitAny AddPrefabPostInit AddPlayerPostInit AddBrainPostInit AddIngredientValues AddCookerRecipe AddModCharacter RemoveDefaultCharacter AddRecipe AddRecipeTab AddAction AddComponentAction AddMinimapAtlas AddStategraphActionHandler AddStategraphState AddStategraphEvent AddStategraphPostInit AddComponentPostInit LoadPOFile RemapSoundEvent AddReplicableComponent AddModRPCHandler GetModRPCHandler SendModRPCToServer GetModRPC SetModHUDFocus AddUserCommand AddVoteCommand ExcludeClothingSymbolForModCharacter worldgen GROUND LOCKS KEYS LEVELTYPE utility GLOBAL modname --name of the mod's folder (i.e. often "workshop-XXXXXXXXX"). for name from modinfo.lua, use GLOBAL.KnownModIndex:GetModFancyName(modname). use GLOBAL.ModInfoname(modname) to get a string with both names (informative for debug purposes). modinfo --contains the environment of the mod's modinfo.lua: all vars in it are stored in this table, including any custom ones. MODROOT env modimport moderror modassert extra CurrentRelease ReleaseID postinitdata postinitfns deprecated AddGameMode Recipe MOD_RPC Everything else that exists (even standard Lua functions... such as require, unpack, next, io.xxx, debug.xxx, assert, error, setmetatable and more) isn't directly available from the mod environment, so by default you must use GLOBAL.xyz to access it. While I'm at it, for posterity... here's a short summary I made of global Klei functions that could be useful to to any mod (including some general table manipulation functions, so you don't have to reinvent your own in each of your mods): Spoiler added global functions by klei (GLOBAL.xx needed to access the standalone ones): util.lua string.split(str,sep) - splits str to parts by specified separator, returns array (ordered table i.e. with sequential numeric keys begining at 1) of the resulting strings table.contains(t, element) - returns true if element exists as a value within t table.containskey(t, k) - returns true if k exists as a key within t. usually simply using "t[k]" instead will suffice (accessing the value of a missing key will give back 'nil' and will not raise an error). table.reverse(t) - returns a new table with the elements of array t in reversed order. table.invert(t) - returns a new table with the key-value pairs of t swapped table.reverselookup(t,val) - looks for val as a value in t and returns its corresponding key (or nil) RemoveByValue(t, val) - removes (as with table.remove()) all occurrences of val in array t. GetTableSize(t) - counts and returns the number of key-value pairs in table t. can be useful for tables without sequential numeric keys, where the value of #t is undefined. math.inf - constant, equal to 123/0. GetRandomItem(choices) GetRandomItemWithIndex(choices) PickSome(num, choices) --handles arrays. modifies given 'choices' table. PickSomeWithDups(num, choices) -- " JoinArrays(...) --concatenates arrays. returns a new sequential array with the contents of all values within the arrays given as arguments (including any duplicate values). ExceptionArrays(tSource, tException) --returns a new array with the difference between the two provided arrays ArrayUnion(...) --merge multiple arrays into a new table that is returned, while only allowing each value once ArrayIntersection(...) --return only values found in all given arrays MergeMaps(...) --merge two map-style tables, overwriting duplicate keys with the latter map's value MergeMapsDeep(...) --merge two map-style tables, overwriting duplicate keys with the latter map's value. subtables are recursed into. MergeKeyValueList(...) SubtractMapKeys(base, subtract) ExtendedArray(orig, addition, mult) --returns a copy table of orig with 'addition' appended 'mult' (or 1) times to the end. GetRandomKey(t) --returns a random key picked from any key-value table t GetRandomMinMax(min, max) --returns rand number between min,max inclusive. why not just use math.random(min,max)?? distsq(v1, v2, v3, v4) --returns the squared distance between points described by numbers or vectors resolvefilepath( filepath, force_path_search ) --looks for a file in the mod and data directories. errors if not found, returns path found otherwise. softresolvefilepath(filepath, force_path_search) --similar to above. returns nil if file not found. kleifileexists(filepath) --hardcoded function. checks if filepath exists. path navigations starts from "/Don't Starve Together/data", so a filepath beginning with "../" corresponds to the game's root folder. from there you can access a file in any folder. --f.ex. GLOBAL.kleifileexists("../bin/fmodex.dll") and GLOBAL.kleifileexists("../bin/dontstarve_steam.exe") will both return true. --same for GLOBAL.kleifileexists(MODROOT.."modmain.lua") --if filepath is not found then nothing is returned, otherwise filepath is returned. --NOTE: filename is CASE SENSITIVE. isnan(x) --true if x ~= x e.g. isnan(0/0) isinf(x) --true if x is inf or -inf isbadnumber(x) --true if isinf(x) or isnan(x) weighted_random_choice(t) --t is a key-value table of choice-weight (weight between 0.0 and 1.0). returns a weigthed random key of t. PrintTable(t) --returns a multilne string detailing the contents of t, including any sub-tables within it (infinite recursion) shuffleArray(t) --randomly shuffles array t (modifies it) and returns t. shuffledKeys(t) --returns a new array with the keys of table t shuffled randomly. sortedKeys(t) --returns a new array with the keys of table t sorted from smallest to largest. deepcopy(t) --returns a full (arbitrarily deep) copy of table t including coipes of all its subtables, if any. LinkedList = Class() --functions: Append(), Remove(), Head(), Tail(), Clear(), Count(), Iterator() table.setfield(Table,Name,Value) table.getfield(Table,Name) table.findfield(Table,Name) table.findpath(Table,Names,indx) checkbit(x, bit) string.random(Length, CharSet) --Length: number. CharSet: string, optional; e.g. %l%d for lower case letters and digits function HexToRGB(hex) --Returns the 0 - 255 color of a hex code function RGBToPercentColor(r, g, b) --Returns the 0.0 - 1.0 color from r, g, b parameters function HexToPercentColor(hex) --Returns the 0.0 - 1.0 color from a hex parameter Link to comment 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