Hornete Posted February 13, 2019 Share Posted February 13, 2019 For my mod I wanna make a couple of tuning values for my armor ARMORBRAMBLE I tried doing local tuning = GLOBAL.TUNING and then placing some tuning values of my own right after but they just wouldn't work on the custom armor I have unless I use the tuning values of an already existing armor. Any help is appreciated Thank you Link to comment Share on other sites More sharing options...
Ultroman Posted February 13, 2019 Share Posted February 13, 2019 Simply doing local tuning = GLOBAL.TUNING tuning.MYVARIABLE = 8 should work, as long as you set them before you do AddPrefab. Example: G = GLOBAL T = G.TUNING RECIPETABS = G.RECIPETABS Recipe = G.Recipe Ingredient = G.Ingredient T.ARMOR_CACTUS = 450 T.ARMOR_CACTUS_ABSORPTION = .8 T.ARMOR_CACTUS_DMG = 17 local armor_cactus = Recipe("armor_cactus", { Ingredient("armorwood", 1), Ingredient("cactus_meat", 12)}, RECIPETABS.WAR, {SCIENCE = 1} ) armor_cactus.atlas = "images/inventoryimages/armor_cactus.xml" Link to comment Share on other sites More sharing options...
CarlZalph Posted February 13, 2019 Share Posted February 13, 2019 Just don't forget to put a 'local' in front of those things, otherwise you're populating the global table. G = GLOBAL -> local G = GLOBAL Link to comment Share on other sites More sharing options...
Hornete Posted February 13, 2019 Author Share Posted February 13, 2019 9 hours ago, Ultroman said: Simply doing local tuning = GLOBAL.TUNING tuning.MYVARIABLE = 8 should work, as long as you set them before you do AddPrefab. Example: G = GLOBAL T = G.TUNING RECIPETABS = G.RECIPETABS Recipe = G.Recipe Ingredient = G.Ingredient T.ARMOR_CACTUS = 450 T.ARMOR_CACTUS_ABSORPTION = .8 T.ARMOR_CACTUS_DMG = 17 local armor_cactus = Recipe("armor_cactus", { Ingredient("armorwood", 1), Ingredient("cactus_meat", 12)}, RECIPETABS.WAR, {SCIENCE = 1} ) armor_cactus.atlas = "images/inventoryimages/armor_cactus.xml" I still keep on crashing,[00:03:07]: [string "scripts/components/armor.lua"]:37: attempt to perform arithmetic on field 'condition' (a nil value) That leads me to these 3 lines in the armor lua of the games code 36 function Armor:GetPercent(amount) 37 return self.condition / self.maxcondition 38 end Im not sure what i'm doing wrong, sorry for bothering you again. P.S. It only works when I put in existing tuning values like TUNING.MARBLEARMOR = whatever So i'm not sure what to do. modmain.lua armor_bramble.lua Link to comment Share on other sites More sharing options...
Ultroman Posted February 13, 2019 Share Posted February 13, 2019 Are you doing this for DS or DST? Your naming is wrong TUNING.ARMOR_BRAMBLE = 280 TUNING.ARMOR_BRAMBLE_ABSORPTION = .65 TUNING.ARMOR_BRAMBLE_DMG = 22.5 and here you try to use them inst.components.armor:InitCondition(TUNING.ARMORBRAMBLE, TUNING.ARMORBRAMBLE_ABSORPTION) Link to comment Share on other sites More sharing options...
YakumoYukari Posted February 14, 2019 Share Posted February 14, 2019 TUNING does not need GLOBAL. Link to comment Share on other sites More sharing options...
Ultroman Posted February 14, 2019 Share Posted February 14, 2019 (edited) It does need it in modmain.lua, and that is the only place it needs it (maybe also in modinfo.lua). The reason is, modmain.lua is being run outside the global environment of the game (before the game is actually running, and the global environment is being initialized), while the code inside a prefab or any other included script file in a mod, are run by the game as part of the game i.e. within the global environment. So, modmain has to access the global environment through an exposed reference to this global environment, and that reference is aptly named GLOBAL. This GLOBAL reference exposes almost all the data in the game's global environment, and while the mods are being processed during initialization of the game and starting of the server, the global environment is enriched and altered by mods iteratively, which is why we have the "priority" variable in the modinfo.lua. It tells us the order in which the mods should be loaded, and that has a HUGE impact on which mods are compatible with each other. Edited February 14, 2019 by Ultroman Link to comment Share on other sites More sharing options...
YakumoYukari Posted February 15, 2019 Share Posted February 15, 2019 Generally, you're right. It is necessary to call GLOBAL to access environment. But TUNING is the exception for the need of GLOBAL. In mods.lua function CreateEnvironment, there's environment definition. ... local env = { -- lua pairs = pairs, ipairs = ipairs, print = print, math = math, table = table, type = type, string = string, tostring = tostring, Class = Class, -- runtime TUNING=TUNING, -- worldgen GROUND = GROUND, LOCKS = LOCKS, KEYS = KEYS, LEVELTYPE = LEVELTYPE, -- utility GLOBAL = _G, modname = modname, MODROOT = MODS_ROOT..modname.."/", } ... As you can see, TUNING is actually listed in there. Which means you don't need to call GLOBAL to get TUNING. Variables in TUNING mostly(all of them I think?) exists for the constructor of the game, implementing 'constants' not be in Lua. So It is actually needed to be constructed in the environment side. No one cares though 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