PDA

View Full Version : Referencing a Window with a string...



Blackfoot
August 7th, 2015, 09:42
I want to change the visibility of one of my number controls based on the state of a cycler... I can do it with a bunch of if-then-else checks but it seems easy enough to build the name of the number control from the cycler value... basically the cycler sets a 'sense' and there is a number control associated with each sense... I want to turn the ones that aren't active, invisible.

function onValueChanged()
sFDType = getValue();
window.fdsight.setVisible(false);
window.fdhearing.setVisible(false);
window.fdsmell.setVisible(false);
window.fdtaste.setVisible(false);
window.fdtouch.setVisible(false);
window.fdunusual.setVisible(false);
if sFDType == "" then
window.fdsight.setVisible(true);
elseif sFDType == "Hearing" then
window.fdhearing.setVisible(true);
elseif sFDType == "Smell" then
window.fdsmell.setVisible(true);
elseif sFDType == "Taste" then
window.fdtaste.setVisible(true);
elseif sFDType == "Touch" then
window.fdtouch.setVisible(true);
elseif sFDType == "Unusual" then
window.fdunusual.setVisible(true);
end
endThis way works.. but it's not very elegant.
I'd like to be able to just set a variable to
sFDType = "fd" .. sFDType;
and then identify the window from it's name... but if I do
window.sFDType.setVisible(true);
it doesn't view the sFDType as the window name. Is there a simple trick do doing this?

Moon Wizard
August 7th, 2015, 15:32
You can try:

sFDType = "fd" .. sFDType:lower()
if window[sFDType] then
window[sFDType].setVisible (true)
else
window.fdsight.setVisible (true)
end

Regards,
JPG

Blackfoot
August 7th, 2015, 16:09
That worked.. thanks. I could have sworn I tried some variant of that... hmm. Cool.