FlawlessHair Posted March 15, 2016 Share Posted March 15, 2016 Hello. I'm trying to check the type of a variable. If the player starts mining the rock with a golden tool, the rock will change it's LootTable to a better one. I already have most of the code done. I've already done it with trees, and it that works perfectly. The problem with rock is that I cannot check what type the rock is. With trees I can easily check the growth of it, and set the loot table according to that. With rocks, I tried setting a local variable in the top: local rocktype = "" And then in each initialization of rocks I would set the rocktype: local function rock1_fn() local inst = baserock_fn("rock", "rock", "full") if not TheWorld.ismastersim then return inst end rocktype = "rock1" inst.components.lootdropper:SetChanceLootTable('rock1') return inst end Although I now have a sneaking suspicion that this variable isn't as local as I thought, and that the last rock ever initialized is what sets the type of all the rocks, because everytime I mine a rock, it has the same type, no matter how it looks in game. And that type differs on each server I create. One time it drops gold. Another time it only drops rocks. So, if I'm right and that variable isn't as local as I thought, what can I do? Is there a good way to check what type of rock this is? Link to comment Share on other sites More sharing options...
Muche Posted March 15, 2016 Share Posted March 15, 2016 It seems to me that you want to check the name of the prefab, i.e. the value of inst.prefab. For rocks it's one of rock1, rock2, rock_flintless, rock_flintless_med, rock_flintless_low, rock_moon. Well, rocktype defined outside the function like that is indeed local (in regard to the file, so it's not global as in part of _G table), but it's not local in regard of particular instance of a prefab, it's shared between all instances; it's more akin to class field. Link to comment Share on other sites More sharing options...
FlawlessHair Posted March 16, 2016 Author Share Posted March 16, 2016 (edited) Aha! Thank you for the answer. Can I then write inst.prefab.name or will inst.prefab return the string I'm looking for? Another question: How can I declare a variable that is only assigned to the prefab itself, if the declaring of the prefab happens in the bottom of the script? (Lua seems to handle declaring variables in a weird way that I'm not used to from Java or c#) EDIT: Did a short amount of testing. Just using inst.prefab as a string was enough to return the name of it. Yay! Thanks! Can you still answer me the other question? Edited March 16, 2016 by FlawlessHair Link to comment Share on other sites More sharing options...
Muche Posted March 16, 2016 Share Posted March 16, 2016 Since Lua is a dynamic language, you can assign field to a prefab instance simply by inst.varname = <value> within rock1_fn. This technically won't create a local variable, it will set given value to index "varname" of associative array inst. Also, a prefab is just a class (Class being defined in class.lua) that creates prefab instances via assigned factory method (in this case rock1_fn). Link to comment Share on other sites More sharing options...
FlawlessHair Posted March 16, 2016 Author Share Posted March 16, 2016 Oh. So instead of writing local varname = <value> I write inst.varname = <value>? That sounds simple. Link to comment Share on other sites More sharing options...
Maris Posted March 16, 2016 Share Posted March 16, 2016 Make your mod compatible with Mineable Gems please. Thanks. Link to comment Share on other sites More sharing options...
FlawlessHair Posted March 16, 2016 Author Share Posted March 16, 2016 1 hour ago, Maris said: Make your mod compatible with Mineable Gems please. Thanks. What if I instead just added an option for gems to pop from rocks? The thing is, this mod is quite a bit bigger than just rocks. It is supposed to being a balance mod, to a lot of stuff, so having other mods enabled that also try to balance will kind of defeat the purpose. 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