Jump to content

Anyone know how to change Class functions post init? (for Moisture:LongUpdate)

Recommended Posts

    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)

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
Link to comment
Share on other sites

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