PDA

View Full Version : Help me softcode this headache code


Camaro
01-26-2011, 02:39 AM
Ok, so what I have is a list of namespaces of the characters in the scene for a GUI, and every time the namespace button is pressed it cycles to the next namespace. Currently I have this hardcoded, because I can't figure out how to softcode it. I've tried a for loop that loops through an array list of all the namespaces, for example:

global string $nsList[];
global string $Namespace;
string $curNs = `button -q -label namespaceBtn`;
string $list11[] = `ls -recursive 1 "Global_Scale"`;
int $size = `size($list11)`;
for($i=0;$i<$size;$i++)
{
if($curNs == $nsList[$i]) //$i
{
$ElevenNamespace = $nsList[$i+1]; //$i+1
button -e -label $Namespace namespaceBtn;
}
}

The problem with this is it loops through to the end of the code. What I need it to do is compare the current namespace given by the label of the button itself with the one in the namespace list. If it matches, it goes to the next one and updates accordingly, and then somehow break out of the loop without continuing to the end, so basically it goes to the end of the namespace list.

Perhaps I'm way over complicating this and there is some magical solution, but I have spent far too long trying to figure out what it is with no results. Currently the full code is hardcoded to only support 3 rigs at a time, and obviously hardcoding is bad practice, so I need any help I can get.

jschieck
01-26-2011, 02:17 PM
and then somehow break out of the loop without continuing to the end, so basically it goes to the end of the namespace list.you had the answer in your question. use break;for ($c in `ls`) {
if ($c == "persp") {
print ($c + " --- found it!\n");
break;
}
print ($c + "\n");
}

Robert Bateman
01-26-2011, 04:10 PM
Have you considered using an optionVar to store the namespace index?

Camaro
01-26-2011, 05:37 PM
you had the answer in your question. use break;for ($c in `ls`) {
if ($c == "persp") {
print ($c + " --- found it!\n");
break;
}
print ($c + "\n");
}

Pretty sure I tried that but it gave me some error. Perhaps I used it wrong.

@Other guy: no, but I doubt it would make a difference.

EDIT: Ok, got it working. Thanks for the help :)

CGTalk Moderation
01-26-2011, 05:37 PM
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.