Thread: Function sharing
-
January 14th, 2021, 17:55 #1
- Join Date
- Dec 2015
- Location
- Boston, MA
- Posts
- 167
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>
Code:<script file="scripts/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.
-
January 14th, 2021, 18:22 #2
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!
-
January 14th, 2021, 19:38 #3
- Join Date
- Dec 2015
- Location
- Boston, MA
- Posts
- 167
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.
-
January 14th, 2021, 20:40 #4
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-ScopePrivate 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