Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

What is the best way to get the absolute value of a number?

Asked by
OBenjOne 190
6 years ago
Edited 6 years ago

I have a script that works:

X = math.random(-10,10) --this doesn't have to be math.random
if X < 0 then
    X = X*-1
end
print (X)

But I'm wondering if there is a better way, especially if I'm trying to get the absolute value of multiple numbers, possibly vector 3.

0
I want to use this to get how far two parts are apart. OBenjOne 190 — 6y
0
math.abs Vulkarin 581 — 6y
0
So I just put X = math.abs(X) ? Is that right? If so that was just what I was looking for! OBenjOne 190 — 6y
0
Ok I checked. It is right. Post as an answer so I can accept. Thanks! OBenjOne 190 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago
math.abs()
0
Thanks. Always nice to get a few reputation points! OBenjOne 190 — 6y
0
Thankyou, this helped greatly with my draggable inventory. FaultyScript 0 — 4y
Ad

Answer this question