PDA

View Full Version : Undeclared Variable Problem


Dichotomy
10-10-2003, 11:36 PM
OK, so I am trying to create a GUI window that will show the lights in a scene and have a second window that will allow you to link or unlink the light from every object in the scene... my problem is that the $lightNum variable works almost the whole script but then, when called for in the button command, it says that it is undeclared...??
I know this might not be the prettiest script, but it is just for practice more than anything. If anyone can tell me why the error is occuring I would appreciate it.
Here's the script:

global string $lightTransfer;
global string $lightsArray[];
proc link()
{
global string $lightTransfer;
global string $lightsArray[];
string $objects[] = `ls -g -dag`;
string $current;
string $winLinkName = "linkWindow";
string $linkMain = "lightLinkWindow";
if (`window -exists $winLinkName`)
{
deleteUI $winLinkName;
}

window -t "linkWindow" $winLinkName;
scrollLayout;
columnLayout;
frameLayout -l $lightTransfer -cll true;
for ($current in $objects)
{
rowColumnLayout -nc 1 -cw 1 500 ($linkMain);
text $lightTransfer;
checkBox -l $current -onc ("lightlink -light $lightTransfer -object $current") -ofc ("lightlink -break -light $lightTransfer -object $current");
setParent $linkMain;
}
showWindow $winLinkName;
}


global proc lights()
{


string $sel[] =`ls -lights`;
string $currentLights;
string $winName = "lightControls";
string $main = "mainWindow";
global string $lightTransfer;
global string $lightsArray[];
int $lightNum = 1;
if (`window -exists $winName`)
{
deleteUI $winName;
}


window -t "lightControls" $winName;
scrollLayout;
rowColumnLayout -nc 1 -cw 1 700 ($main);
for ($currentLights in $sel)
{
$lightsArray[$lightNum] = $currentLights;
frameLayout -l $currentLights -cll true;
rowColumnLayout -nc 3 -cw 1 400 -cw 2 100 -cw 3 100;
text $lightsArray[$lightNum];
attrFieldSliderGrp -min -1 -max 10 -at ($currentLights +".intensity");
button -l "links" -c ("link");
button -l "loadLight" -c ("$lightTransfer = $lightsArray[$lightNum]*****ERROR HERE*****");
setParent $main;
$lightNum++;
}
showWindow $winName;
}

ajk48n
10-11-2003, 06:00 AM
Try making $lightNum global.

spinlock
10-11-2003, 06:14 AM
I think the problem you're having here is that when you create the button command, $lightNum is defined in the current proc. So when you do any `prints` from within lights() it looks ok.

What I think is actually happening is that command is being run via user generated event AFTER $lightNum falls out of scope.

Note that you don't have problems with $lightsArray or $lightTransfer which makes me think that all you have to do is also define $lightNum as global...

CGTalk Moderation
01-16-2006, 07:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.