Sign in to follow this  

[Solved] Chaining Original Function

Recommended Posts

zetake    12

How do you currently chain original function?


Because this:

AddComponentPostInit("resurrectable", function(self, inst)
    local _CanResurrect = self.CanResurrect
    self.CanResurrect = function(self, cause)
        _CanResurrect(self, cause)

    local _FindClosestResurrector = self.FindClosestResurrector
    self.FindClosestResurrector = function(self, cause)
        _FindClosestResurrector(self, cause)

    local _DoResurrect = self.DoResurrect
    self.DoResurrect = function(self, res, cause)
        _DoResurrect(self, res, cause)

Doesn't work for me.


I've tried AddComponentPostInit and AddClassPostConstruct.

And modifications do works, but they doesn't chain original functions.

So my mod is worthless in this case.

Edited by zetake

Share this post

Link to post
Share on other sites
CarlZalph    5026

It's missing the handling of return parameters.  I wrote a thing a little bit back showing the boilerplate for function hooking here:


  • Like 1
  • Thanks 1

Share this post

Link to post
Share on other sites
zetake    12

So I didn't return value returned by original function.

Thanks, now it works.


Ah, I see.

If a function has a return, you not only have to call original function,

but you also have to return value returned by that original function or post edited value of it.


Because original function is meant to return value to wherever it was called from,

but after modification it return value to your modified function instead,

and your modified function doesn't pass it on, by default.

So, if you don't return it like me, it will fail for you also.

Edited by zetake
  • Sanity 1

Share this post

Link to post
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
Sign in to follow this