PDA

View Full Version : Help With Accessing Controls On Other (Peer) Subwindows



dulux-oz
May 16th, 2014, 10:23
Hi Guys,

Yeah, I'm at that stage again - been coding all day and now I'm tired and beating my head against my favourite brick wall again. :)

I've got a windowreferencecontrol (wrc01) sitting on a subwindow (sw01) and I need to perform a getWindows() call (wrc01.getWindows()) from a second subwindow (sw02). Both subwindows are children of the same parent window (main).

I've got my call as follow:


for kKey,oWindow in pairs(parentcontrol.window.sw01.subwindow.wrc01.ge tWindows()) do
{stuff happeneds};
end

Unfortunately I'm getting the following error:


Script Error: [string "sw02_script.lua"]:73: attempt to index field 'subwindow' (a nil value)

Any help would be appreciated.

Thanks

Trenloe
May 16th, 2014, 17:06
Firstly, getWindows() will not work on a windowreferencecontrol, it is usually used with windowlist controls.

In reference to the subwindow being nil, I recommend that you step through your control hierarchy and make sure that you are where you think you are with the code you're using. For debugging your control hierarchy I recommend taking it one step at a time and output the control name/class name to the console. This should, with just a couple of Debug.console commands, give you an idea if you are accessing controls you think you are.

For example:

Debug.console("parentcontrol = " .. parentcontrol.getName());
Debug.console("parentcontrol.window = " .. parentcontrol.window.getClass());
Debug.console("parentcontrol.window.sw01 = " .. parentcontrol.window.sw01.getName());

Depending on what the actual element you are referencing is (a control or a window instance) you may need to swap getName (for a control) with getClass (for a window instance), or vice versa.

dulux-oz
May 16th, 2014, 18:14
Firstly, getWindows() will not work on a windowreferencecontrol, it is usually used with windowlist controls.

Sorry, typo in my post (told you I was tired).

Post should read <corrected post>:

I've got a windowinstance (wi01) sitting on a subwindow (sw01) and I need to perform a getWindows() call (wrc01.getWindows()) from a second subwindow (sw02). Both subwindows are children of the same parent window (main).

I've got my call as follow:


for kKey,oWindow in pairs(parentcontrol.window.sw01.subwindow.wi01.get Windows()) do
{stuff happens};
end

Unfortunately I'm getting the following error:


Script Error: [string "sw02_script.lua"]:73: attempt to index field 'subwindow' (a nil value)

</corrected post>

This, unfortunately, doesn't change the jist of the question - I'm not even getting down to the windowinstance as it's bombing-out at the parent subwindow (sw01).


In reference to the subwindow being nil, I recommend that you step through your control hierarchy and make sure that you are where you think you are with the code you're using. For debugging your control hierarchy I recommend taking it one step at a time and output the control name/class name to the console. This should, with just a couple of Debug.console commands, give you an idea if you are accessing controls you think you are.

For example:

Debug.console("parentcontrol = " .. parentcontrol.getName());
Debug.console("parentcontrol.window = " .. parentcontrol.window.getClass());
Debug.console("parentcontrol.window.sw01 = " .. parentcontrol.window.sw01.getName());

Depending on what the actual element you are referencing is (a control or a window instance) you may need to swap getName (for a control) with getClass (for a window instance), or vice versa.

Yeah, I was trying to avoid having to do that (as I said, I was tired) - I was hoping that someone would see an "obvious" mistake that they could point out while I slept - if no-one had found anything then I was going to take your suggested route when I get back to it tomorrow.

Thanks Tren

dulux-oz
May 16th, 2014, 18:51
Found it!

Forgot to put in a <fastinit /> in my <subwindow> definition.

I REALLY have to stop coding when I'm tired! :p

Cheers

Trenloe
May 16th, 2014, 18:54
Firstly, getWindows() won't work against a window instance. A window instance is a single instance of a window, it doesn't have any other windows it is a window in itself. https://www.fantasygrounds.com/refdoc/windowinstance.xcp

To go back to the jist of your question, I'm not 100% sure as I don't have access to your XML, but I think it is the subwindow.wi1 portion that could be failing. without seeing your XML, I think that subwindow is actually the window instance wi1

See what Debug.console("parentcontrol.window.sw01.subwindow = " .. parentcontrol.window.sw01.subwindow.getClass()); shows you, this might be the window instance you are looking for. But, remember that getWindows will not work on this - you only have one window instance and at this point you probably have the reference to it.

dulux-oz
May 16th, 2014, 19:42
Gawd, I can't even get my corrects right tonight!

Let's try again - third time's the charm, as they say.

Right, its not a windowinstance nor is it a windowreferencecontrol, it's a windowlist!

Sometimes I should just walk away...

Anyway, as I said in Post #4, I found the issue - I needed to <fastinit /> in my <subwindow> definition.

I've tested it, it works, and now I'm going to bed!

Cheers

Trenloe
May 16th, 2014, 20:36
Sometimes I should just walk away...
Yeah. ;)