PDA

View Full Version : If statement


RaGzMaN
10-20-2005, 11:38 AM
////////////// Hi there, figured it out, thanks

Hi there,

Any one get what im on about here?

If i want to say,

If the varible is x then do this and print "youve done this"
if the varible isnt x then print "its not this".

Ive just started learning so bare with me but i see it as.


int $t = X;

proc eg (int $temp)
{

if ($temp == X) //if it is x

CreateNURBSTorus; //Then make a torus for example

else print "Its not X"; //if its not x then write



}



spm ($loc);

I get all that, my question is what do i have to add to be able to say,
if it is X then make the torus AND print "you made a torus" but still allow for it not to be X.

thanks

Stucky
10-20-2005, 12:52 PM
Hey dude. Its simple, you can add another if condition: I changed X to 2. and made a global proc, so you can run it from outside, just for text purposes. Source the script and in Maya run eg(2);


int $temp = 2;

global proc eg (int $temp)
{

if ($temp == 2) //if it is x

CreateNURBSTorus; //Then make a torus for example

if ($temp == 2)

print "You made a torus";

else print "Its not X"; //if its not x then write


}

RaGzMaN
10-20-2005, 01:35 PM
Hi there, thanks for your reply, having looked at it for a bit, you dont even have to use a global proc:
int $attr = 2;



proc eg (int $temp)

{



if ($temp == 2)



CreateNURBSTorus;



if ($temp == 2)



print "You made a torus";



else print "Its not X"; //if its not x then write





}

eg ($attr);

Stucky
10-20-2005, 02:49 PM
ok. glad it helped. Yhea, I just used a global proc for making it easier to me..;)

EigenPuff
10-20-2005, 04:55 PM
It would be clearer if instead of a second if, you would use { } to make a compound statement - i.e.



proc eg (int $temp)
{

if ($temp == 2) //if it is x
{
CreateNURBSTorus; //Then make a torus for example
print "You made a torus";
}
else
{
print "Its not X"; //if its not x then write
print "\n.. or Y"; //do a second step in the "else" block
}
}

RaGzMaN
10-20-2005, 09:35 PM
Thanks for your reply,

Is there a way to refer to an already declaired varible outside of a proc from within a proc without using a global varible?

Stucky
10-20-2005, 10:46 PM
I think there is no problem, as long as, you declare the variable and "run" the proc, at the same time, the variable dont need to be inside the proc. Please someone correct me if I'm wrong.



-S

CGTalk Moderation
10-20-2005, 10:46 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.