PDA

View Full Version : Subwindows and "back referencing" query



celestian
February 28th, 2018, 02:12
I'm trying to call a function from within 2 subwindows all the way back to the top. I'm having trouble finguring it out tho.

The setup is this.

windowclass(readycheck)
-subwindow(main)
--windowclass(ready_check_main)
---subwindow(main_user)
----windowclass(ready_check_entry_user)

From within ready_check_entry_user I want to have a button_checkbox via onValueChanged() refer back to a function in "readycheck".

I'm having trouble figuring out the "path" BACK to readycheck. window.function refers to the script within the windowclass "ready_check_entry_user" so that's not helpful. Been trying to figure out parentcontrol but that doesn't seem to get things back where I need either.

Anyone have some tips on how to reference backwards?

damned
February 28th, 2018, 02:22
Side trip - can you not do this by referencing the DB directly?

celestian
February 28th, 2018, 02:31
Side trip - can you not do this by referencing the DB directly?

There is no node associated with the subwindow that the button_checkbox resides. It's non-persistent data that I just need to know they clicked at that moment. I'm triggering a oob notify.

I'll attach the xml file.

Trenloe
February 28th, 2018, 03:19
You're probably going to have to string parentcontrol and subwindow together: https://www.fantasygrounds.com/refdoc/subwindow.xcp

When I need to work these out I will use lots of Debug.console commands outputting the control name (https://www.fantasygrounds.com/refdoc/windowcontrol.xcp#getName) or window instance class name (https://www.fantasygrounds.com/refdoc/windowinstance.xcp#getClass).

So things like: window.getClass() or parentcontrol.getName() and then string them together - window.parentcontrol.getName() etc..

You'll get some nil errors, but it usually helps to go through it a few times to work out the exact hierarchy and how you can string the various API references together.

celestian
February 28th, 2018, 03:28
You're probably going to have to string parentcontrol and subwindow together: https://www.fantasygrounds.com/refdoc/subwindow.xcp

When I need to work these out I will use lots of Debug.console commands outputting the control name (https://www.fantasygrounds.com/refdoc/windowcontrol.xcp#getName) or window instance class name (https://www.fantasygrounds.com/refdoc/windowinstance.xcp#getClass).

So things like: window.getClass() or parentcontrol.getName() and then string them together - window.parentcontrol.getName() etc..

You'll get some nil errors, but it usually helps to go through it a few times to work out the exact hierarchy and how you can string the various API references together.

That was what I was trying to do and I got to window.parentcontrol.subwindow. After that I couldn't get any further back up. I'll look at the notes you linked and see if I can figure out why.

Trenloe
February 28th, 2018, 03:33
That was what I was trying to do and I got to window.parentcontrol.subwindow. After that I couldn't get any further back up. I'll look at the notes you linked and see if I can figure out why.
Did you try window.parentcontrol.subwindow.window as the next step?

celestian
February 28th, 2018, 04:04
Did you try window.parentcontrol.subwindow.window as the next step?

Yup, here is the code I ran from the button and the output I got.




function onButtonPress()
local sName = User.getUsername();
window.notifyReadyCheck(sName,1);
Debug.console("PC0","window",window);
Debug.console("PC1","window.getClass()",window.getClass());
Debug.console("PC2","window.subwindow",window.subwindow);
Debug.console("PC3","window.parentcontrol",window.parentcontrol);
Debug.console("PC4","window.parentcontrol.getName()",window.parentcontrol.getName());
Debug.console("PC6","window.parentcontrol.subwindow",window.parentcontrol.subwindow);
Debug.console("PC7","window.parentcontrol.subwindow.getClass()",window.parentcontrol.subwindow.getClass());
Debug.console("PC8","window.parentcontrol.subwindow.window",window.parentcontrol.subwindow.window);
end





Runtime Notice: s'PC0' | s'window' | windowinstance = { class = ready_check_entry_user, node = nil, x,y,w,h = 371,295,246,45 }
Runtime Notice: s'PC1' | s'window.getClass()' | s'ready_check_entry_user'
Runtime Notice: s'PC2' | s'window.subwindow' | nil
Runtime Notice: s'PC3' | s'window.parentcontrol' | subwindow = { x,y,w,h = 0,15,246,45 }
Runtime Notice: s'PC4' | s'window.parentcontrol.getName()' | s'main_user'
Runtime Notice: s'PC6' | s'window.parentcontrol.subwindow' | windowinstance = { class = ready_check_entry_user, node = nil, x,y,w,h = 371,295,246,45 }
Runtime Notice: s'PC7' | s'window.parentcontrol.subwindow.getClass()' | s'ready_check_entry_user'
Runtime Notice: s'PC8' | s'window.parentcontrol.subwindow.window' | nil
Script Error: [string ""]:1: attempt to index field 'window' (a nil value)



As you can see the "main_user" is right here:

windowclass(readycheck)
-subwindow(main)
--windowclass(ready_check_main)
---subwindow(main_user)<--------------
----windowclass(ready_check_entry_user)

Trenloe
February 28th, 2018, 04:08
OK, so window = ready_check_entry_user and window.parentcontrol.subwindow also = ready_check_entry_user.

So you've gone up then back down with subwindow.

How about window.parentcontrol.window?

Trenloe
February 28th, 2018, 04:10
The "Scope" section here might also give you some ideas: https://www.fantasygrounds.com/wiki/index.php/Developer_Guide_-_Rulesets_-_Scripting#Script_Block_Scope

For this you're probably going to need something like: window.parentcontrol.window.parentcontrol.window

Bidmaron
February 28th, 2018, 04:15
Celestian, I usually give up and create a temporary node in these cases because I can never walk back up very far. I create the node and then delete it when I'm done. A kluge, but I get brain damage trying to walk up window/subwindow hierarchies like that.

celestian
February 28th, 2018, 04:46
Celestian, I usually give up and create a temporary node in these cases because I can never walk back up very far. I create the node and then delete it when I'm done. A kluge, but I get brain damage trying to walk up window/subwindow hierarchies like that.

It is quite the challenge but this kinda thing sucks me in and makes me figure it out. Makes it easier down the road when I need to do it again... you are right tho the temporary node would make it a lot easier ;)


The "Scope" section here might also give you some ideas: https://www.fantasygrounds.com/wiki/index.php/Developer_Guide_-_Rulesets_-_Scripting#Script_Block_Scope

For this you're probably going to need something like: window.parentcontrol.window.parentcontrol.window

You are correct. The way I figured it out was really kludgy but it worked.

So the first thing I did was call what I knew was valid from "ready_check_entry_user" in a <script> section like this.

function onButtonPress()
local sName = User.getUsername();
window.parentcontrol.readyPressed(sName,1);
end

Then at main_user I added another script section with the same code (the above is sent to main_user <script>)

function readyPressed(sUser,nCheck)
Debug.console("utility_readycheck.xml","main_user","TESTING");
window.parentcontrol.readyPressed(sUser,nCheck);
end

and then in "main"

function readyPressed(sUser,nCheck)
Debug.console("utility_readycheck.xml","main","TESTING");
window.readyPressed(sUser,nCheck);
end

and then finally in readycheck I added the real "readyPressed(sUser,nCheck);

By the time I got to "main" I had figured out it was

window.parentcontrol.window.parentcontrol.window.r eadyPressed(sName,1);

It was kinda klunky but I eventually figured out the path. That whole backwards thing was confusing but I think next time I'll have a much better idea how to do it. Thanks all for the tips!

Bidmaron
February 28th, 2018, 15:53
Thanks for sharing, Celestian. You da man!

Minty23185Fresh
February 28th, 2018, 22:51
Have you figured this out yet?
Oops nevermind

Trenloe
February 28th, 2018, 22:55
Have you figured this out yet?
I've gone four or five times up successfully, just as you did in post 7.
It looks to me like you went in circles. window goes up, subwindow goes down.

I think you have to use the names?
Like window.main_user.window.main.window

Maybe it's the ready checks instead...
Yep - it has been figured out. What I mentioned in post #9 was the solution.

You can't use control/windowclass actual names to go up from the bottom of a GUI hierarchy - you have to use referential names such as window and parentcontrol - because "window" doesn't return the top most window, it returns the current window the control code is in.

celestian
March 1st, 2018, 00:50
Have you figured this out yet?
Oops nevermind

Replace "subwindow" with "parentcontrol" and it works out going backwards. Using subwindow takes you back down.