Trying to change negative numbers to postive numbers.

Trying to change negative numbers to postive numbers.

Anonymous
Not applicable
2,374 Views
2 Replies
Message 1 of 3

Trying to change negative numbers to postive numbers.

Anonymous
Not applicable
I am trying to change numbers like -5, -23.46 to turn into 5, 23.46. I hear abs was supposed to do that but it still returns as negative.

int $n = -26;
abs $n;
print $n;


This returns -26.

Am I doing something completly wrong? I am quite new to mel but it isn't the longes code... Is there a diffrent way of turning negative nr to positve while keeping positive nr positive?
0 Likes
2,375 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
because abs doesn't change the variable in place, you have to capture the result like so.....
(brackets are so you don't corrupt the namespace and get that hateful redefination of variable name error!!!...which python doesn't suffer from because it has dynamic typing and is way more cool.)

{
int $d = -26.0;
$d= `abs($d)`;
print $d;
}
0 Likes
Message 3 of 3

Anonymous
Not applicable
Thanks for the help 🙂

The maya help file only shows this
$f=-123;
abs $f;
// Result: 123 //

abs <<-1, -2.432, 555>>;
// Result: <<1, 2.432, 555>> //

So I tought I had enought, but clearly not. Thanks again 🙂
0 Likes