Nappy Posted September 23, 2020 Share Posted September 23, 2020 So I have been working with understanding PostInit() because it seems like the most advantageous way to edit components so that on future patches the mod stays viable. I have had success adding new component functions AND replacing old component functions using AddComponentPostInit(). However, now I am trying to add a variable to the Class of a component function and could use some help. The example of what I have successfully done by editing a Component file was to add this to component/childspawner ... local Childspawner = Class(function(self, inst) ... self.rarechild1 = nil self.rarechild2 = nil self.rarechild3 = nil self.rarechildchancex3 = 0.1 ...end) function ChildSpawner:SetRareChildx3(childname1, childname2, childname3, chance) self.rarechild1 = childname1 self.rarechild2 = childname2 self.rarechild3 = childname3 self.rarechildchancex3 = chance end function ChildSpawner:SpawnChild(target, prefab, radius) ...if self.rarechild1 and math.random() < self.rarechildchancex3 then local pickrarechild = math.random(1,3) if pickrarechild == 1 then childtospawn = self.rarechild1 elseif pickrarechild == 2 then childtospawn = self.rarechild2 elseif pickrarechild == 3 then childtospawn = self.rarechild3 end end ... end Thus, using ComponentsPostInit() I have figured out how to add function ChildSpawner:SetRareChildx3 and edit already existing function ChildSpawn:SpawnChild, BUT I NEED HELP adding to the Class(Function(...)) the variables I am calling to save the 3 different rare children please. THANKS! Link to comment https://forums.kleientertainment.com/forums/topic/121935-need-help-with-using-addcomponentpostinit-to-add-to-classfunction/ Share on other sites More sharing options...
Nappy Posted September 23, 2020 Author Share Posted September 23, 2020 Solved: For those interested, I found my answer by looking at this post: I did not use the hack, but it helped me understand AddClassPostConstruct() and I used... AddClassPostConstruct("components/childspawner", function(self) self.rarechild1 = nil self.rarechild2 = nil self.rarechild3 = nil self.rarechildchancex3 = 0.1 end) I do have another question for you other modders out there, do you know how to reduce the amount of text I am replacing with AddComponentPostInit()? As it is, for components.childspawner:SpawnChild(), there are 90+ lines of code, but I only need to add 10 lines of code and I am not altering anything already written. However, the way I am using AddComponentPostInit() I am replacing the whole function when really I just wanted to add these few lines of code to it. Just hit me back if you know how to do this, thx! Link to comment https://forums.kleientertainment.com/forums/topic/121935-need-help-with-using-addcomponentpostinit-to-add-to-classfunction/#findComment-1373629 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