DMsGuild
  1. #1

    Overriding function

    So far I have found 2 ways of overriding a function, but I'm in a situation where I'm not sure which applies.

    1. The function is in a lua file and the lua file is included from base.xml (or, really any xml file) -
    <script name="CharacterManager" file="scripts/manager_character.lua" />
    If that's the case, then I can use the name: CharacterManager.whateverFunctionName = new function

    2. The function is part of a script section that is included directly as part of a xml file and only referenced in there
    For this I can use merge to override the entire script section instead of just the one function -
    <root>
    <template name="pc_traitdiebase">
    <traitdiebase merge="replace">
    <script>
    function onInit()

    But now I've hit a new situation.

    3. The function is in a lua file, but that lua file is not referenced as part of the base.xml. Instead, it is only references once under a windowclass in an xml -
    <windowclass name="npc_skillentry">
    <sizelimits>
    <minimum height="42" />
    </sizelimits>
    <script file="campaign/scripts/npc_skill.lua"/>
    It is never assigned a name for external referencing, so I can't use method 1. But it also doesn't have local code, so method 2 doesn't exactly match either.

    I'm thinking I can make a copy of the lua with an altered name. Then use method 2 to merge the new name as a replacement -
    <script file="campaign/scripts/npc_skill_replace.lua"/>
    Which would mean the new lua file would need to contain all of the functions of the old file even if I am only altering one of them.


    Is there a better method of doing this?

  2. #2
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Newcastle, UK (for a bit)
    Posts
    27,317
    FG Con 16 Fantasy Grounds Online RPG Convention - Postponed New date To Be Confirmed.
    Register at www.fg-con.com for all the latest info.

    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
    Yea, that helps. Though, really, I'd almost rather just copy the file and redo changes following any updates than bother with using super to hop up for 7/8 functions in the file. I mean, I was basically right about my solution except for the "super"/dynamic rebuilding of all the other functions.

    I'm sure others have said this before, but there really needs to be a better way of doing this.

  4. #4
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Newcastle, UK (for a bit)
    Posts
    27,317
    Quote Originally Posted by ApesAmongUs View Post
    Yea, that helps. Though, really, I'd almost rather just copy the file and redo changes following any updates than bother with using super to hop up for 7/8 functions in the file. I mean, I was basically right about my solution except for the "super"/dynamic rebuilding of all the other functions.
    You may not have to use the super calls for functions that you're not overriding. I've done more work with these since I made that post. If the function isn't there in the overriding script then, from my limited testing, I believe it will run the one a layer up.

    So, maybe there is a "better" way of doing this!
    FG Con 16 Fantasy Grounds Online RPG Convention - Postponed New date To Be Confirmed.
    Register at www.fg-con.com for all the latest info.

    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!

  5. #5
    I've just ripped out a lot of functions from an overridden script file I've been working on where I am only overriding 2 of around 12 functions.
    With the 10 I'm not needing stripped out of the new lua script, it still looks like it works as intended, so I would say you're correct Trenloe.
    Happy days if so, saves alot of extra typing

    Cheers, Steve.

  6. #6
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Newcastle, UK (for a bit)
    Posts
    27,317
    Quote Originally Posted by Stv View Post
    I've just ripped out a lot of functions from an overridden script file I've been working on where I am only overriding 2 of around 12 functions.
    With the 10 I'm not needing stripped out of the new lua script, it still looks like it works as intended, so I would say you're correct Trenloe.
    Happy days if so, saves alot of extra typing

    Cheers, Steve.
    Cool! Sorry I misled you initially.
    FG Con 16 Fantasy Grounds Online RPG Convention - Postponed New date To Be Confirmed.
    Register at www.fg-con.com for all the latest info.

    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!

  7. #7
    No harm Trenloe, I appreciated the input, also I've leant a lot from the process

    Cheers, Steve.

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
  •  
SWADE Playlist

Log in

Log in