PDA

View Full Version : Calling WindowControls As Strings



dulux-oz
November 6th, 2014, 04:16
Hi Guys,

Quick question: if I pass a variable (eg sPath="window.subwindow01.subwindow.number01") to a function (eg fpMyFunction(sPath,nValue)) what is the correct syntax for the following:



function fpMyFunction(sPath,nValue)
sPath.setValue(nValue);
end


Where I'm trying to set window.subwindow01.subwindow.number01.setValue(nVa lue)?

Cheers

Trenloe
November 6th, 2014, 10:55
In your example, sPath is a variable that contains the complete control reference name, whereas you need the control object to be able to use API methods against the control. I'm not aware of a method that will allow you to get to the control object using the complete control reference name. To make this work, pass the control object reference to the function, not the control name then you can use .setValue directly against the object.

dulux-oz
November 6th, 2014, 11:02
In your example, sPath is a variable that contains the complete control reference name, whereas you need the control object to be able to use API methods against the control. I'm not aware of a method that will allow you to get to the control object using the complete control reference name. To make this work, pass the control object reference to the function, not the control name then you can use .setValue directly against the object.

OK, so using my example as a starting point, what would be the control reference to the control window.subwindow01.subwindow.number01?

For eg: do I set sPath = window.subwindow01.subwindow.number01 (as opposed to sPath = "window.subwindow01.subwindow.number01")?

Trenloe
November 6th, 2014, 11:14
For eg: do I set sPath = window.subwindow01.subwindow.number01 (as opposed to sPath = "window.subwindow01.subwindow.number01")?
Yes, but you'd need to reference that within a script where the window variable is pointing to the correct window - within a script tied to a control this will be pointing to the window the control resides in, but if you are referencing this within a global script package it won't know what window is and you'll have to either pass/register the window variable in the global script package.

See "Script block scope" here: https://www.fantasygrounds.com/modguide/scripting.xcp

dulux-oz
November 6th, 2014, 11:25
Ok, thanks Tren, I think I've got it sorted now :)