Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Switch statement control.

4 REPLIES 4
Reply
Message 1 of 5
00Six00
654 Views, 4 Replies

Switch statement control.

Hi everyone,

Ive been trying to figure this one out for a few days. I have 6 things that i need to be able to toggle between but i need the switch statement to always begin at "case 0".  Is it possible to make a switch statement always begin at "case 0" when I execute the command and if so, how can i accomplish this? 

4 REPLIES 4
Message 2 of 5
mcw0
in reply to: 00Six00

Not clear what you mean by "always start at case 0".  Can you be more specific?

Message 3 of 5
00Six00
in reply to: mcw0

this is a base example as ive only been playing around with this for the past couple of days. If i needed case 3 on 1 object, i would need to toggle 4 times. Then say i needed case 0 on a different object, i would need to toggle and go through the rest of the switch statement before it reaches case 0 again. I was just wondering if there was a way that once ive reached the desired case, if the switch statement can be reset so that it begins a case 0 once i need it again. 

global proc example()
{
    global int $Toggle;
    string $selections[] = `ls -sl`;
    $Toggle++;
    switch ($Toggle)
    {
        case 0:
                for ($each in $selections)
                {
                    do something;
                }
                break;
        case 1:
                for ($each in $selections)
                {
                    do something;
                }
                break;
        case 2:
                for ($each in $selections)
                {
                    do something;
                }
                break;
        case 3:
                for ($each in $selections)
                {
                    do something;
                }
                break;
        case 4:
                for ($each in $selections)
                {
                    do something;
                }
                break;
        case 5:
                for ($each in $selections)                
                {
                    do something;
                }
                break;
        default:
                $Toggle = 0;
                for ($each in $selections)                
                {
                    do something;
                }
                break;
    }
    
    select -r $selections;
    
}

example();

 

Message 4 of 5
mcw0
in reply to: 00Six00

Why use "toggle"? Don't you know what you want to do with your selection?  Why not just run the command you want on your selection? 

 

I'm sorry that I am failing to see what you are trying to do.  Also, print statements are a great aid in working through your code. 

Message 5 of 5
bradley_henke
in reply to: 00Six00

It your default case you are setting the value to 0, but you immediately increment the value to 1 with the statement "$Toggle++" before the switch statement. I would either set the value to -1 in your default branch, or move the "$Toggle++" after the switch statement.

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report