Starfinder Playlist
  1. #1

    Calling the original function in an overridden function.

    I'm trying to figure out how to call an original function later in the code, that has been overriden/redirected in the onInit() function.


    The onInit looks as follows:

    Code:
    function onInit()
       EffectManager.addEffect = addEffectDuplicateCheck;  
    end
    Then in the overridden function after some functionality has taken place, I then want to call the original function again, given certain conditions.

    Such as in addEffectDuplicateCheck:

    Code:
        if (bFoundDuplicate == false) then
            EffectManager.addEffect = EffectManager.addEffect;     -- attempt at redirecting function back to its original
            EffectManager.addEffect(sUser, sIdentity, nodeCT, rNewEffect, bShowMsg);
        end
    The problem I'm having is that I'm not sure how to call the original EffectManager function again, after the custom code has ran.
    Currently this functionality will put FG into and endless loop, as the function is calling itself continually.

    Is there a way to do this?

    I'd rather not copy the about 90 lines of code from the original EffectsManager.addEffect function, and rewrite it to work in the new .lua.
    As that would be rather messy coding and harder to maintain.
    Last edited by StoryWeaver; December 13th, 2019 at 20:09.
    Extension writer, FGU Backer, Ultimate License holder.

    5E Enhancer (development and support on hold for now)

    Combat Enhancer 5E Classic (no longer officially supported, community support only)

    ps. Do not send PM's for support for the extensions I write, I will not not be able to respond there. Use the relevant forum threads instead so the community can benefit from the replies, thank you.



  2. #2
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,404
    If you override a function in a global script package then you've overridden it. I don't believe the "super" reference for layered scripts works with global packages.

    But, the EffectManager.addEffect function has two custom function calls already built in: fCustomOnEffectAddStart and fCustomOnEffectAddEnd which are specifically there to allow developers to tie in code into that function without having to modify the base function itself. You can set the code for these functions through EffectManager.setCustomOnEffectAddStart(f) and EffectManager.fCustomOnEffectAddEnd(f) where f is a function within your custom code. You'll need to look at the EffectManager.addEffect to see where these run and what you can do with these custom functions.
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  3. #3

    Join Date
    Jun 2013
    Location
    Isanti, MN
    Posts
    2,922
    Quote Originally Posted by Styrmir View Post
    I'm trying to figure out how to call an original function later in the code, that has been overriden/redirected in the onInit() function.

    ...snip...

    Is there a way to do this?

    I'd rather not copy the about 90 lines of code from the original EffectsManager.addEffect function, and rewrite it to work in the new .lua.
    As that would be rather messy coding and harder to maintain.
    Did you try this?

    Code:
    function onInit()
       savedFunction = EffectManager.addEffect;
       EffectManager.addEffect = addEffectDuplicateCheck;  
    end
    Then later:

    Code:
        if (bFoundDuplicate == false) then
            savedFunction(sUser, sIdentity, nodeCT, rNewEffect, bShowMsg);
        end

  4. #4
    Thank you Andraax, that worked!

    I had tried something similar as a global constant, which didn't work. Putting it in the onInit() function however saved the original function into memory correctly.
    Extension writer, FGU Backer, Ultimate License holder.

    5E Enhancer (development and support on hold for now)

    Combat Enhancer 5E Classic (no longer officially supported, community support only)

    ps. Do not send PM's for support for the extensions I write, I will not not be able to respond there. Use the relevant forum threads instead so the community can benefit from the replies, thank you.



  5. #5
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,404
    Sorry, I misunderstood what you were trying to do. Glad Andraax sorted you out! :-)
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
5E Product Walkthrough Playlist

Log in

Log in