Math Functions⚓︎
Warning
The MWSE-mwscript API is deprecated. The documentation found here is for legacy purposes only. None of the following functions can be used directly from Lua.
xArcCos⚓︎
Parameters:
floatangle: The angle to take the trigonometric function of.
Returned:
floatresult: Result of the function.
Provides the inverse trigonometric function arccosine on the given angle.
xArcSin⚓︎
Parameters:
floatangle: The angle to take the trigonometric function of.
Returned:
floatresult: Result of the function.
Provides the inverse trigonometric function arcsine on the given angle.
xArcTan⚓︎
Parameters:
floatangle: The angle to take the trigonometric function of.
Returned:
floatresult: Result of the function.
Provides the inverse trigonometric function arctangent on the given angle.
xArcTan2⚓︎
Parameters:
floatx: The angle to take the trigonometric function of.floaty: The angle to take the trigonometric function of.
Returned:
floatresult: Result of the function.
Provides the inverse trigonometric function arctan2 on y/x.
xBitAnd⚓︎
Parameters:
longleftValue: First value for the bitwise operation.longrightValue: Second value for the bitwise operation.
Returned:
longresult: 1 if the bitwise operation returns true.
This function performs an AND bitwise operation, and returns its result.
| A | B | xBitAnd A B |
|---|---|---|
| 0000 | 0000 | 0000 |
| 0101 | 1010 | 0000 |
| 1100 | 1111 | 1100 |
| 1111 | 0000 | 0000 |
xBitNot⚓︎
Parameters:
longleftValue: Value for the bitwise operation.
Returned:
longresult: 1 if the bitwise operation returns true.
This function performs a NOT bitwise operation, and returns its result.
| A | xBitNot A |
|---|---|
| 0000 | 1111 |
| 0101 | 1010 |
| 1100 | 0011 |
| 1111 | 0000 |
xBitOr⚓︎
Parameters:
longleftValue: First value for the bitwise operation.longrightValue: Second value for the bitwise operation.
Returned:
longresult: 1 if the bitwise operation returns true.
This function performs an OR bitwise operation, and returns its result.
| A | B | xBitOr A B |
|---|---|---|
| 0000 | 0000 | 0000 |
| 0101 | 1010 | 1111 |
| 1100 | 1111 | 1111 |
| 1111 | 0000 | 1111 |
xBitXor⚓︎
Parameters:
longleftValue: First value for the bitwise operation.longrightValue: Second value for the bitwise operation.
Returned:
longresult: 1 if the bitwise operation returns true.
This function performs an XOR bitwise operation, and returns its result.
| A | B | xBitXor A B |
|---|---|---|
| 0000 | 0000 | 0000 |
| 0101 | 1010 | 1111 |
| 1100 | 1111 | 0011 |
| 1111 | 0000 | 1111 |
xCos⚓︎
Parameters:
floatangle: The angle to take the trigonometric function of.
Returned:
floatresult: Result of the function.
Provides the trigonometric function cosine on the given angle.
xDegRad⚓︎
Parameters:
floatangle: An angle, in degrees.
Returned:
floatresult: The value of angle in radians.
This simple function converts from degrees to radians.
xFloatsToLong⚓︎
Parameters:
floatvalue1: First value. Order doesn't matter.floatvalue2: Second value. Order doesn't matter.
Returned:
longresult: Merged value from value1 and value2.
This function retrieves a long value using a pair of floats. It is intended to work around the issue that all globals are really floats.
This work by splitting the long 32-bit value into two 16-bit values and adding a flag to indicate which value maps to the high 16 bits. Argument order doesn't matter.
Warning
MWEdit doesn't like to compile these functions with globals as arguments, and temporary locals will need to be used instead.
Example
long lVal1
long lVal2
float fVal1
float fVal2
set lVal1 to 2147483647
setx fVal1 fVal2 to xLongToFloats lVal1
setx lVal2 to xFloatsToLong fVal1 fVal2
if ( lVal1 == lVal2 )
MessageBox "Success!"
else
MessageBox "Failure!"
endif
Hypot⚓︎
Parameters:
floatx:floaty:
Returned:
floathypotenuse:
xHypot returns the hypotenuse for sides a and b, c = sqrt(aa + bb). Unlike xSqrt this is more efficient than calculating the formula inside the script.
xLongToFloats⚓︎
Parameters:
longvalue: Value to split.
Returned:
floatresult1: First half of the split value.floatresult2: Second half of the split value.
This function stores a long value using a pair of floats. It is intended to work around the issue that all globals are really floats.
This work by splitting the long 32-bit value into two 16-bit values and adding a flag to indicate which value maps to the high 16 bits. Argument order doesn't matter.
Warning
MWEdit doesn't like to compile these functions with globals as arguments, and temporary locals will need to be used instead.
Example
long lVal1
long lVal2
float fVal1
float fVal2
set lVal1 to 2147483647
setx fVal1 fVal2 to xLongToFloats lVal1
setx lVal2 to xFloatsToLong fVal1 fVal2
if ( lVal1 == lVal2 )
MessageBox "Success!"
else
MessageBox "Failure!"
endif
xPow⚓︎
Parameters:
floatbase: Base value.floatexponent: Exponent to calculate.
Returned:
floatresult: Result of the function.
Calculates the value of base raised to exponent.
xDegRad⚓︎
Parameters:
floatangle: An angle, in radians.
Returned:
floatresult: The value of angle in degrees.
This simple function converts from radians to degrees.
xRandomFloat⚓︎
Parameters:
floatminimum: Lowest value to return.floatmaximum: Highest value to return.
Returned:
floatresult: A random value between minimum and maximum.
This function returns a random float value.
xRandomLong⚓︎
Parameters:
longminimum: Lowest value to return.longmaximum: Highest value to return.
Returned:
longresult: A random value between minimum and maximum.
This function returns a random long value.
xShift⚓︎
Parameters:
longvalue: The value to shift.longmagnitude: The number of bits to shift. If negative, the bits will be reverse-shifted.
Returned:
longresult: value, shifted magnitude bits.
This function allows shifting a value by a number of bits equal to magnitude.
xSin⚓︎
Parameters:
floatangle: The angle to take the trigonometric function of.
Returned:
floatresult: Result of the function.
Provides the trigonometric function sine on the given angle.
xSqrt⚓︎
Parameters:
floatvalue: Value to take the square root of.
Returned:
floatresult: Result of the function.
Calculates the square root of value.
xTan⚓︎
Parameters:
floatangle: The angle to take the trigonometric function of.
Returned:
floatresult: Result of the function.
Provides the trigonometric function tangent on the given angle.