Discuss Scratch

GT1016
Scratcher
11 posts

Converting negative into positive and vice versa

What operator or script could turn, say, -3 into 3, 4 into -4, 129 into -129, etc.? I'm using this to make inverted movement. Thanks!
Catscratcher07
Scratcher
1000+ posts

Converting negative into positive and vice versa

(() * (-1))
Za-Chary
Scratcher
1000+ posts

Converting negative into positive and vice versa

Another option is:

((0) - ())
GT1016
Scratcher
11 posts

Converting negative into positive and vice versa

Thanks!
Zydrolic
Scratcher
1000+ posts

Converting negative into positive and vice versa

Za-Chary wrote:

Another option is:

((0) - ())
And if you have an edgecase where you exclusively want to convert negative to positive, use absolute value:
([abs v] of ())
Scratch137
Scratcher
1000+ posts

Converting negative into positive and vice versa

Zydrolic wrote:

(#5)

Za-Chary wrote:

Another option is:

((0) - ())
And if you have an edgecase where you exclusively want to convert negative to positive, use absolute value:
([abs v] of ())
And, to complete the family, you can multiply the absolute value by -1 or subtract it from 0 to convert only positive numbers to negative numbers:

(([abs v] of ()) * (-1))
((0) - ([abs v] of ()))

Powered by DjangoBB