DICE PACKS BUNDLE
  1. #1

    Character Wizard overrides of onInit

    I have overriden character wizard charwizard.lua to override the onInit call and modify the collections it builds. Works as it always has. But now I find that unless I copy in every single function and header definitions - it will not work with the LVL UP button in the character sheet. This makes no sense to me. Why is LUA/FGU/whatever forcing me to do this? I've tried calling super things but unless I call the actual functions and define them all in my override they will seem to go off to some other version of the code.

    Totally confused. For now I'm going to copy the entire charwizrd.lua and stamp my onInit stuff in it also - but this seems way overkill and unfriendly to manage just to get some onInit stuff working the character wizard - which always works. It's just when it comes at the same charwizard.lua that I don't override from the charsheet LVL UP button that it seems to go nuts. Unless I copy in and override all the code in that lua.

    Would really like to not have to do this. Is there a way?
    Free(Forums/Forge) Extension(FGU 5E):
    Paid (Forge) Extension(FGU 5E):

  2. #2
    Super only works in scripts attached to controls, not global scripts. Each global script runs in its own scope and knows nothing about other scopes. Super works with controls because FG performs the control overrides and can walk back up the chain. For global scripts there is no such relationship. You either override the entire thing, including the global name that function names are prefixed by, or you create a new global script and figure out a way to interact with the existing global script, either via function replacement or well-known callback registration mechanisms. I also don't think super works in a fully or partially overridden windowclass, but I might be wrong about that.

    More information about scripting and the override mechanisms can be found in the Scripting page on the wiki, of which I'm sure you're already aware.

  3. #3
    Quote Originally Posted by darrenan View Post
    Super only works in scripts attached to controls, not global scripts. Each global script runs in its own scope and knows nothing about other scopes. Super works with controls because FG performs the control overrides and can walk back up the chain. For global scripts there is no such relationship. You either override the entire thing, including the global name that function names are prefixed by, or you create a new global script and figure out a way to interact with the existing global script, either via function replacement or well-known callback registration mechanisms. I also don't think super works in a fully or partially overridden windowclass, but I might be wrong about that.

    More information about scripting and the override mechanisms can be found in the Scripting page on the wiki, of which I'm sure you're already aware.
    That is very valuable - but depressing - information to hear. I suspected that was the case, as it seems more if something comes in from outside of the normal functionality where .lua is defined it requires every piece of logic/structure/etc. that it touches to be added into the override. I usually can work around it by limiting it to just a few things - but not this time.

    Much appreciated for that information - as I never knew the reasoning behind why I've had to do that sort of thing in the past.
    Free(Forums/Forge) Extension(FGU 5E):
    Paid (Forge) Extension(FGU 5E):

  4. #4
    It would be far simpler if everyone used named scripts and named script function calls...like CharacterWizard.collectRaces(), et.al. Then you could just override the functions as needed...but I don't think that would work in this particular case, because it sounds like you are adding to onInit rather than replacing specific functions? Anyways, my 2 coppers...
    aka Laendra

    (Discord: Laendra#9660)
    Ultimate license (FGC/FGU)
    Current Timezone : Central (CDT) (GMT -5)
    OP: 3317036507 / 2369539

    My opinions are my own and represent no entity other than myself

    Extension Support Discord: https://discord.gg/gKgC7nGpZK

    Extensions = risk to your gaming experience. If you haven't tested out the extensions in your campaign before your gaming session, turn them off. If you don't backup your campaigns regularly, you're doing it wrong.


  5. #5
    Quote Originally Posted by deer_buster View Post
    It would be far simpler if everyone used named scripts and named script function calls...like CharacterWizard.collectRaces(), et.al. Then you could just override the functions as needed...but I don't think that would work in this particular case, because it sounds like you are adding to onInit rather than replacing specific functions? Anyways, my 2 coppers...
    Unfortunately they reference a lot of .lua files directly in .xml files which are never named.
    Free(Forums/Forge) Extension(FGU 5E):
    Paid (Forge) Extension(FGU 5E):

  6. #6
    I would agree with deer_buster that things would be easier if coders kept the code attached to windows and controls to a minimum, generally only those things that actually involve the UI, and moved as much ruleset logic as possible into named scripts. This is the equivalent of the well-known model-view-controller (MVC) method of code separation which has been around almost as long as UIs have been around. Also known as "separation of concerns". If you can make good general purpose functions in named scripts, then those can be called by multiple control scripts as needed. However, if you put ruleset logic into a control script, then it's likely that you will be duplicating that code somewhere down the line (in a similar control in a different windowclass) which turns into a maintenance headache.

  7. #7
    Quote Originally Posted by SilentRuin View Post
    I have overriden character wizard charwizard.lua to override the onInit call and modify the collections it builds. Works as it always has. But now I find that unless I copy in every single function and header definitions - it will not work with the LVL UP button in the character sheet. This makes no sense to me. Why is LUA/FGU/whatever forcing me to do this? I've tried calling super things but unless I call the actual functions and define them all in my override they will seem to go off to some other version of the code.

    Totally confused. For now I'm going to copy the entire charwizrd.lua and stamp my onInit stuff in it also - but this seems way overkill and unfriendly to manage just to get some onInit stuff working the character wizard - which always works. It's just when it comes at the same charwizard.lua that I don't override from the charsheet LVL UP button that it seems to go nuts. Unless I copy in and override all the code in that lua.

    Would really like to not have to do this. Is there a way?
    manager_charwizard.lua does a ton of operations on the charwizard window after opening it during "function impCharacter" (the function called by the LVL UP button). So perhaps your onInit is firing as intended but something else is subverting your expected outcome?
    My Forge creations: https://forge.fantasygrounds.com/crafter/9/view-profile
    My GitHub: https://github.com/MeAndUnique
    Buy me a coffee: https://ko-fi.com/meandunique
    Discord: MeAndUnique#6805

  8. #8
    Quote Originally Posted by MeAndUnique View Post
    manager_charwizard.lua does a ton of operations on the charwizard window after opening it during "function impCharacter" (the function called by the LVL UP button). So perhaps your onInit is firing as intended but something else is subverting your expected outcome?
    Darrenan's explanation explained why its happening and makes sense from what I'm seeing. When the window lua logic gets fired from charsheet the entire branch it triggers is out of scope and must be defined in the override. That is also what I'm seeing.
    Free(Forums/Forge) Extension(FGU 5E):
    Paid (Forge) Extension(FGU 5E):

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