Jump to content

Recommended Posts

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 by Aquaterion
Link to comment
https://forums.kleientertainment.com/forums/topic/66808-modifying-functions/
Share on other sites

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 by Muche

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...