Norfeder Posted February 1, 2018 Share Posted February 1, 2018 I want to extract the wait times from fishingrod.lua for other uses inst:AddComponent("fishingrod") inst.components.fishingrod:SetWaitTimes(4, 40) I know that I have to add these function to fishingrod component so that I can extract the wait times. But I don't know how to add new function to / change existing components. Can anyone help? thanks function FishingRod:GetMinWaitTimes() return self.minwaittime end function FishingRod:GetMaxWaitTimes() return self.maxwaittime end Link to comment https://forums.kleientertainment.com/forums/topic/86998-how-to-add-new-functions-to-components/ Share on other sites More sharing options...
Aquaterion Posted February 1, 2018 Share Posted February 1, 2018 modmain.lua is where you need to do this AddComponentPostInit("fishingrod", function(self) --adding a new fn function self:GetMaxWaitTimes() return self.maxwaittime end --overwriting an existing fn local oldSetWaitTimes = self.SetWaitTimes --self.<functionName> function self:SetWaitTimes(min, max) print("New Min: " .. min .. " | New Max: " .. max)--runs before old function oldSetWaitTimes(self, min, max)--call the old function with the same parameters except adding self as the first parameter, since it is not being invoking via colon(:) print("WaitTimes Changed")--runs after old function end end) BUT, if you want to just fetch those values without doing the above, you could also just do this where ever you need them inst:AddComponent("fishingrod") inst.components.fishingrod:SetWaitTimes(4, 40) local minwait = inst.components.fishingrod.minwaittime--will be 4 local maxwait = inst.components.fishingrod.maxwaittime--will be 40 Link to comment https://forums.kleientertainment.com/forums/topic/86998-how-to-add-new-functions-to-components/#findComment-998320 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