PF2E Playlist
  1. #1

    Add to a class' onInit() - replace / merge?

    If I want to add functionality to the end of a class' onInit() function, do I have to completely replace the onInit() and add my code to the end?

    Is there any way to effectively merge it? That is to say, have the original onInit() run, then have my additional function run right afterwards?

    Thanks.

  2. #2

    Join Date
    May 2016
    Location
    Jacksonville, FL
    Posts
    2,071
    Blog Entries
    7
    This might at least get you going in the right direction:

    Code:
    function onInit()
    	-- ensure the CoreRPG scripts load
    	if super and super.onInit then
    		super.onInit()
    	end
    	-- new code goes here
    end
    I use this in one of the windowclasses in a ruleset I work on so that I only have to maintain my code and not have to duplicate the CoreRPG scripts (and maintain them every time they get updated).

  3. #3
    Quote Originally Posted by Talyn View Post
    This might at least get you going in the right direction:

    Code:
    function onInit()
    	-- ensure the CoreRPG scripts load
    	if super and super.onInit then
    		super.onInit()
    	end
    	-- new code goes here
    end
    I use this in one of the windowclasses in a ruleset I work on so that I only have to maintain my code and not have to duplicate the CoreRPG scripts (and maintain them every time they get updated).
    That is exactly what I was looking for. Thanks!

  4. #4
    Now let's say that script, the one with the original onInit() has a local variable declared at the top of the script like so:

    Code:
    local nSomeVariable;
    Is there any way for my code to set/get it?

  5. #5

    Join Date
    May 2016
    Location
    Jacksonville, FL
    Posts
    2,071
    Blog Entries
    7
    No clue, I'm too new at the Lua side of things to have a grip on how the layering works, but my (extremely limited) understanding is that local variables/tables only exist within the functions they're defined in. If you go poking around the CoreRPG + ruleset scripts you'll find a lot of similar things being defined in each script so I'm guessing it'd be easier to just replicate the one you're wanting in your own function to make sure you're getting the correct value.

  6. #6
    damned's Avatar
    Join Date
    Mar 2011
    Location
    Australia
    Posts
    22,878
    Blog Entries
    1
    Im pretty sure local is local...

    MoreCore - Generic Ruleset
    --- Projects ---
    Extensions | Tutorials | MoreCore | MoreCore Themes | Call of Cthulhu | Maelstrom | FG Con

Thread Information

Users Browsing this Thread

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

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 Storm Kings Thunder Playlist

Log in

Log in