Aquaterion Posted April 29, 2016 Share Posted April 29, 2016 (edited) Is there a way to modifiy a function inside a prefab and still keep the references to the other functions in the same prefab(without modifying base file)? For example: If I want to modify the function of "GrowTall" in evergreens.lua, I'd have to edit table "growth_stages" as that is where the "GrowTall" function is called, but because of that I would also have to make copies of all the other "GrowSize" functions, as well as "SetSize" functions. Atm I was trying to do with by using "AddPrefabPostInit" If you know anything about this, less me know, even if its a no. Edited April 29, 2016 by Aquaterion Link to comment Share on other sites More sharing options...
Muche Posted April 29, 2016 Share Posted April 29, 2016 (edited) Would something like this work for you? local function evergreen_postinit(inst) local growth_stages = inst.components.growable ~= nil and inst.components.growable.stages or nil if growth_stages == nil or type(growth_stages) ~= "table" then moderror("growth_stages not found for " .. tostring(inst)) return end local idx = 1 while idx <= #growth_stages and growth_stages[idx].name ~= "tall" do idx = idx + 1 end if idx > #growth_stages then moderror("tall growth_stage not found for " .. tostring(inst)) return end local old_tall_growfn = growth_stages[idx].growfn growth_stages[idx].growfn = function(inst) -- do something here old_tall_growfn(inst) -- or here end end AddPrefabPostInit("evergreen", evergreen_postinit) Edited April 29, 2016 by Muche Link to comment Share on other sites More sharing options...
Aquaterion Posted April 29, 2016 Author Share Posted April 29, 2016 Yea I did figure something similar to that; inst.components.growable.stages[4].fn = newfn (or something like this) i still had to copy that fn, because the stuff I wanted to change was in it, and adding it before or after would make it technically do what I changed while also doing it in the old function it without the change 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