Mel Q


#1

Hello, I’m new to mel and am just starting the DVD from gnomon for introduction to mel.

However, I’m perplexed by a simple conditional…example that he gave. Seemed to work for him but not for me. I can get conditionals to work in other ways but not this particular string. Any insight would be greatly appreciated.

First off he created a polySphere

then ran the string

//scaleZ is a variable

float $scaleZ = getAttr pSphere1.scaleZ;

//change the color to red when $scaleZ bigger than 2

if ($scaleZ > 2);
setAttr “lambert1.color” 1 0 0;
else
setAttr “lambert1.color” 0 0 1;

The error I get is "// Error: else //

// Error: Syntax error //"

I can run each section individually, but when running the conditional things seem to run into a snag with “else.” Any thoughts? Also, I also tried it with the {} before the setAttr lines. Didn’t work this way either. I’m sure I’m missing something pretty simple.

Thanks in advance. When learning mel, you got to just love syntax.


#2

hi, quite simply:

float $scaleZ = getAttr pSphere1.scaleZ;
if ($scaleZ > 2)
{
setAttr “lambert1.color” 1 0 0;
}
else
{
setAttr “lambert1.color” 0 0 1;
}


#3

Dude you rock. There wasn’t a ; at the end of - if ($scaleZ > 2)

I went back to the video and he didn’t have it either. I just inserted as I’m in the habit of ending every line now with ;

But it does make sense. The logic of the thought is continuing not ending.

Thanks bro for cluing me in.


#4

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.