Lingo Dictionary > A-C > abs() |
![]() ![]() ![]() |
abs()
Syntax
abs (
numericExpression
)
Description
Math function; calculates the absolute value of a numerical expression. If numericExpression
is an integer, its absolute value is also an integer. If numericExpression
is a floating-point number, its absolute value is also a floating-point number.
The abs
function has several uses. It can simplify the tracking of mouse and sprite movement by converting coordinate differences (which can be either positive or negative numbers) into distances (which are always positive numbers). The abs
function is also useful for handling mathematical functions, such as sqrt
and log
.
Example
This statement determines whether the absolute value of the difference between the current mouse position and the value of the variable startV
is greater than 30 (since you wouldn't want to use a negative number for distance). If it is, the foreground color of sprite 6 is changed.
if (the mouseV - startV).abs > 30 then sprite(6).forecolor = 95
![]() ![]() ![]() |