What do you do when you are thirsty? You go get a drink... If I'm not thirsty, I'll not get a drink. For simplicity I'm going to make an int called thirsty.
int $ma_thirsty = 1; //This represents me being thirsty...
Now I've defined that I'm thirsty so Maya will understand this. Then I'll make Maya ask me if I'm thirsty and if I am I want her to tell me that she'll bring me a glass of water in a minute. If I'm not thirsty I'll make her tell me to let her know when I am. I'll write down the code first and then go through it:
if ($ma_thirsty == 1){
print "I'll get you a glass of water in a minute";
}
Then you can go :
if ($ma_thirsty == 0){
print "Let me know if you get thirsty then:)";
}
But in Maya you can also say "if variable is true --> do this", "else --> do that". So we could rewrite this:
if ($ma_thirsty == 1){
print "I'll get you a glass of water in a minute";
}
else{
print "Let me know if you get thirsty then:)";
}
What we say here is "if variableis 1, get glass of water". "If it's anything else, let me know". So if the variable was 0, 2, 3, 4, 6 or whatever, but 1 it will print "Let me know if you get thirsty then:)"... Let's say we want the if statement to print something else when the variable is 2, but still print the other things we already stated we could use something called else if:
if ($ma_thirsty == 1){
print "I'll get you a glass of water in a minute";
}
else if ($ma_thirsty == 2){
print "Get it yourself";
}
else{
print "Let me know if you get thirsty then:)";
}
So now Maya takes "2" into consideration too while filtering all the other numbers out in the else- section. 1 of course will still be in the first if statement.
We could have declared the variable as a string too. We could check if the string said "yes" or "no" instead of 1 and 0. 2 could have been "maybe" and so on. Notice the syntax here:
if(){
}
What you want to check goes in between the brackets, the commands you want to execute based on the check goes between the curly braces. There are two ways of writing the curly braces. Right now I'm in a conversion. I used to write it like this below because it is easier to read, but now I save a line by writing it like above. If you check the scripts Alias wrote you can see they also write it like this.
if ()
{
}
|