DICE PACKS BUNDLE
  1. #1

    Function sharing

    I have a, probably, silly question.

    If I have a template in a windowclass that references a lua file and I want to initate a function in that file from a different lua file in a different template in a different windowclass in the same file?

    So for example

    Code:
    <windowclass name ="main">
        <sample_1 name="firstTemplate">
    </windowclass>
    
    <windowclass name ="sub">
         <sample_2 name="secondTemplate">
    </windowclass>
    If you go into the sample_1 template there is
    Code:
    <script file="scripts/primary.lua" />
    Can I add a lua file to sample_2 that calls a function from primary.lua?

    I tried window.functionName(), but it doesn't want to work. I know I'm missing something simple, I just can't see it.
    Wesley Toma-Lee
    Lead Developer
    Nerd Eye Industries
    https://www.nerdeyeindustries.com

  2. #2
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,362
    You can call a script in another control using <GUI hierarchy>.<controlname>.<function>

    This relies on navigating the GUI hierarchy, and also the GUI controls being in place. It therefore can be an unreliable approach - especially if the code is being called during onInit functions or on GUI entities that have multiple tabs.

    Not knowing your full GUI hierarchy, I can't suggest an accurate hierarchy string. But, if those windowclasses are subwindows you will probably need something like main.subwindow.firstTemplate.functionName()

    If you're doing a operation involving data, I'd strongly recommend you code directly against the database than the GUI.
    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
    OK, this shows a poor choice in naming from me. When you say main.subwindow, I assume you don't mean to refer to the windowclass I called main, but main as in main branch of the file. In otherwords if that first subwindow was named "first" instead of "main", then I would still use the keyword main.
    Wesley Toma-Lee
    Lead Developer
    Nerd Eye Industries
    https://www.nerdeyeindustries.com

  4. #4
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,362
    Quote Originally Posted by statik37 View Post
    OK, this shows a poor choice in naming from me. When you say main.subwindow, I assume you don't mean to refer to the windowclass I called main, but main as in main branch of the file. In otherwords if that first subwindow was named "first" instead of "main", then I would still use the keyword main.
    GUI hierarchy uses either the name of a control or one of the reserved variable names. "main" is not a reserved variable name, so I was indeed referring to the naming used. But, as I said, I don't know your hierarchy, so what I posted was only a guess - which could be way off.

    Details on script block scope, and reserved variables names, can be found in the Wiki 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!

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

Log in

Log in