Jump to content

Recommended Posts

Anyone know how to change a Class's function post init, similar to AddPrefabPostInit?
I want to change Moisture:LongUpdate inside this https://pastebin.com/q23J9pt
 
Any way to get a simple print() inside the LongUpdate function here?
 
function Moisture:LongUpdate(dt)
    self:OnUpdate(dt)
end

 

AddComponentPostInit("moisture",function(comp)
    local old_LongUpdate = comp.LongUpdate -- remember the original one
    comp.LongUpdate = function(self,dt,...) -- change the LongUpdate to our new one (use "..." to get every parameter following dt, so it is also compatible in case devs are adding more parameters)
        print("moisture LongUpdate. dt is "..tostring(dt))
        if old_LongUpdate ~=nil then -- if there was an original one
            return old_LongUpdate(self,dt,...) -- call it (and return it, just in case it returns sth important)
        end
    end
end)

I'm not 100% sure, if "self" is correct in this case, I always forget how it is correct. So test it and in case the print of dt is the correct number value, then the code is fine. If the print of dt is nil, then remove "self".

Keep in mind that you can also change components within AddPrefabPostInit.
So in case you only want to change moisture for you specific character, you can also change the inst.components.moisture.LongUpdate within AddPrefabPositInit("yourcharacter,...).

Edited by Serpens

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...