DICE PACKS BUNDLE
  1. #1

    Help with CT.lua

    I've run into a problem with adding functionality to the CT.lua file. I'm hoping I'm just being stupid and someone can help me out.

    I've have a new template_ct.xml file that contains the following code

    Code:
    <template name="list_ctbox_host" merge="join">
            <windowlist name="list">
                <anchored to="contentanchor">
                    <top anchor="bottom" relation="relative" offset="5" />
                    <left offset="-30" />
                    <right offset="10" />
                    <bottom parent="" offset="-55" />
                </anchored>
                <datasource>.list</datasource>
                <class>ct_entry</class>
                <empty font="list-empty-ct" textres="ct_emptylist" />
                <script file="ct/scripts/new_ct.lua" />
            </windowlist>
        </template>
    Which points to my new ct.lua file (new_ct.lua).
    This all works fine, as currently I have just copied the entiretly of the old ct.lua file into my new one and added in my new functions.

    I thought I could use 'super.onInit()' to call the original onInit function (as well as doing it for most of the other original functions in the ct.lua file also), but this throws an error 'attempt to index global 'super' ( a nil value).

    So my question is :
    Is it possible to use the 'super' functionality in ct.lua, and if so what am I doing wrong?

    Cheers, Steve.

  2. #2
    Templates don't support merge attribute; so you are overriding based on that code.

    You would need to copy the original template and script, then modify to fit your needs; or possibly use some sort of stepped template (original redefined as list_ctbox_host_step; and new list_ctbox_host inherits).

    Regards,
    JPG

  3. #3
    Thanks Moon Wizard, I guess I'll leave my code 'as is' then with the copied contents of the original file.

    Cheers, Steve.

  4. #4
    Quote Originally Posted by Moon Wizard View Post
    Templates don't support merge attribute; so you are overriding based on that code.

    You would need to copy the original template and script, then modify to fit your needs; or possibly use some sort of stepped template (original redefined as list_ctbox_host_step; and new list_ctbox_host inherits).

    Regards,
    JPG
    Is there anyway to let me preserve the original ct.lua code that is currently running? Otherwise any extension that ever modifies ct.lua will by default kill any other extensions modifications - true?
    Free(Forums/Forge) Extension(FGU 5E):
    Paid (Forge) Extension(FGU 5E):

  5. #5
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,361
    Quote Originally Posted by SilentRuin View Post
    Is there anyway to let me preserve the original ct.lua code that is currently running? Otherwise any extension that ever modifies ct.lua will by default kill any other extensions modifications - true?
    As this is code that runs in a control (windowlist), any extensions or layered rulesets that change the code will be layering on top of the original code. You can access the original code by using the super variable - you may need to write some code to cycle through all the layers of super variables until you find the highest level instance - in case there are multiple extensions overriding it.

    Access a function the next level up by using super.<function name> - but check for "super" first - e.g. to check for a higher level onInit() function use something like: if super and super.onInit then ...

    Do a search for super. in any layered ruleset to see some examples.

    Some info on script block scope and the super variable here: https://fantasygroundsunity.atlassia...pt-Block-Scope
    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!

  6. #6
    Quote Originally Posted by Trenloe View Post
    As this is code that runs in a control (windowlist), any extensions or layered rulesets that change the code will be layering on top of the original code. You can access the original code by using the super variable - you may need to write some code to cycle through all the layers of super variables until you find the highest level instance - in case there are multiple extensions overriding it.

    Access a function the next level up by using super.<function name> - but check for "super" first - e.g. to check for a higher level onInit() function use something like: if super and super.onInit then ...

    Do a search for super. in any layered ruleset to see some examples.

    Some info on script block scope and the super variable here: https://fantasygroundsunity.atlassia...pt-Block-Scope
    Used super before and that was what I tried before looking up why it did not work - as you can see from this post I glommed onto - he had same issue where super is nil. Evidently when the .lua is referenced in a template it does not have super. All mine were nil - like this guys - and I was looking for a way not to stomp all the code.

    If you are saying its automagically layered on top even though the super is not present - can I just add in the code I need overriden or new in the ct.lua reference I've given the template code and leave the rest blank? See original post here to see what I'm talking about.
    Free(Forums/Forge) Extension(FGU 5E):
    Paid (Forge) Extension(FGU 5E):

  7. #7
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,361
    I don't have free time to get into the guts of this.

    And looking at the 5E code, there's a comment above the windowlist template where ct.lua is used saying "<!-- NOTE: Redefine list box template to make sure that new ct.lua script used -->" Whereas some other rulesets don't don't use a template, they use a control directly in the XML - so you can override the code directly.

    I have no idea about the details of what you're actually trying to do and, like I say, I don't have time to get dragged into this. You may need to look into what MW mentions in post #2 above.
    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!

  8. #8
    Quote Originally Posted by Trenloe View Post
    I don't have free time to get into the guts of this.

    And looking at the 5E code, there's a comment above the windowlist template where ct.lua is used saying "<!-- NOTE: Redefine list box template to make sure that new ct.lua script used -->" Whereas some other rulesets don't don't use a template, they use a control directly in the XML - so you can override the code directly.

    I have no idea about the details of what you're actually trying to do and, like I say, I don't have time to get dragged into this. You may need to look into what MW mentions in post #2 above.
    No worries. Unless Moon Wizard has some magic up his sleeve - I think the way 5E was written my original assumption holds. There can only ever be one modification to this area of the code ever. Or in terms of extensions running at the same time - there can be only one.
    Free(Forums/Forge) Extension(FGU 5E):
    Paid (Forge) Extension(FGU 5E):

  9. #9
    The CT was a PITA to play with, probably 'cos of my lack of knowledge of all things FG and LUA related
    Although I think there is a timer addition to the combat tracker that will work still alongside my legendary assistant extension (when I get round to adjusting some bounds), maybe looking into that may help @Silentruin?

    Cheers, Steve.

  10. #10
    Quote Originally Posted by Stv View Post
    The CT was a PITA to play with, probably 'cos of my lack of knowledge of all things FG and LUA related
    Although I think there is a timer addition to the combat tracker that will work still alongside my legendary assistant extension (when I get round to adjusting some bounds), maybe looking into that may help @Silentruin?

    Cheers, Steve.
    I don't have any trouble doing the code - its my ever present desire to minimize the footprint (stomping on other extensions) that I worry about For now my plan is to just get it working then if I put it up in DMsG will have to have horrific warnings about the compatibility issues because the way 5E references those .lua files through a template makes only one option available if you have to modify them. STOMP THEM ALL. Which I'm not a fan of - but we will see if there is not some magic or something someone knows about. My bet - is unlikely
    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
  •  
STAR TREK 2d20

Log in

Log in