Cogito, ergo sum
Legacy:UnrealScript Language Reference/Language Functionality
Contents
UnrealScript Language Reference[edit]
This subpage is part of a document by Tim Sweeney. The Unreal Wiki has been granted permission to host it. Please don't make any edits to these pages other than basic formatting of the text. If you have more to say on a topic here, please start a new Wiki page on it, for example from UnrealScript or Unreal Engine, and then add a "related topics" section to the very end of a page here.
Tim Sweeney
Epic MegaGames, Inc.
tim@epicgames.com
http://www.epicgames.com
Language Functionality[edit]
Built-In Operators And Their Precedence[edit]
UnrealScript provides a wide variety of C/C++/Java-style operators for such operations as adding numbers together, comaring values, and incrementing variables. The complete set of operators is defined in Object.u, but here is a recap. Here are the standard operators, in order of precedence. Note that all of the C style operators have the same precedence as they do in C.
Operator | Types it applies to | Meaning |
$ |
string | String concatenation |
*= |
byte, int, float, vector, rotation | Multiply and assign |
/= |
byte, int, float, vector, rotation | Divide and assign |
+= |
byte, int, float, vector | Add and assign |
-= |
byte, int, float, vector | Subtract and assign |
|| |
bool | Logical or |
&& |
bool | Logical and |
& |
int | Bitwise and |
| |
int | Bitwise or |
^ |
int | Bitwise exlusive or |
!= |
all | Compare for inequality |
== |
all | Compare for equality |
< |
byte, int, float, string | Less than |
> |
byte, int, float, string | Greater than |
<= |
byte, int, float, string | Less than or equal to |
>= |
byte, int, float, string | Greater than or equal to |
~= |
float, string | Approximate equality (within 0.0001), case-insensitive equality |
<< |
int, vector | Left shift (int), Forward vector transformation (vector) |
>> |
int, vector | Right shift (int), Reverse vector transformation (vector) |
+ |
byte, int, float, vector | Add |
- |
byte, int, float, vector | Subtract |
% |
float | Modulo (remainder after division) |
* |
byte, int, float, vector, rotation | Multiply |
/ |
byte, int, float, vector, rotation | Divide |
dot |
vector | Vector dot product |
cross |
vector | Vector cross product |
** |
float | Exponentiation |
The above table lists the operators in order of precedence (with operators of the same precedence grouped together). When you type in a complex expression like "1*2+3*4", UnrealScript automatically groups the operators by precedence. Since multiplication has a higher precedence than addition, the expression is evaluated as "(1*2)+(3*4)".
The "&&" (logical and) and "||" (logical or) operators are short-circuited: if the result of the expression can be determined solely from the first expression (for example, if the first argument of && is false), the second expression is not evaluated.
In addition, UnrealScript supports the following unary operators:
Operator | Types it applies to | Meaning |
! |
bool | Logical not |
- |
int, float | negation |
~ |
int | bitwise negation |
++, -- |
int, float | Increment or Decrement (either before or after a variable) |
more on this topic in the Wiki: Operators |
General-Purpose Functions[edit]
Integer functions:
- int Rand( int Max )
- Returns a random number from 0 to Max-1.
- int Min( int A, int B )
- Returns the minimum of the two numbers.
- int Max( int A, int B )
- Returns the maximum of the two numbers.
- int Clamp( int V, int A, int B )
- Returns the first number clamped to the interval from A to B.
Floating point functions:
- float Abs( float A )
- Returns the absolute value of the number.
- float Sin( float A )
- Returns the sine of the number expressed in radius.
- float Cos( float A )
- Returns the cosine of the number expressed in radians.
- float Tan( float A )
- Returns the tangent of the number expressed in radians.
- float Atan( float A )
- Returns the inverse tangent of the number expressed in radians.
- float Exp( float A )
- Returns the constant "e" raised to the power of A.
- float Loge( float A )
- Returns the log (to the base "e") of A.
- float Sqrt( float A )
- Returns the square root of A.
- float Square( float A )
- Returns the square of A = A*A.
- float FRand()
- Returns a random number from 0.0 to 1.0.
- float FMin( float A, float B )
- Returns the minimum of two numbers.
- float FMax( float A, float B )
- Returns the maximum of two numbers.
- float FClamp( float V, float A, float B )
- Returns the first number clamped to the interval from A to B.
- float Lerp( float Alpha, float A, float B )
- Returns the linear interpolation between A and B.
- float Smerp( float Alpha, float A, float B )
- Returns an Alpha-smooth nonlinear interpolation between A and B.
Unreal’s string functions have a distinct Basic look and feel:
- int Len( coerce string[255] S )
- Returns the length of a string.
- int InStr( coerce string[255] S, coerce string[255] t)
- Returns the offset into the first string of the second string if it exists, or -1 if not.
- string[255] Mid ( coerce string[255] S, int i, optional int j )
- Returns the middle part of the string S, starting and character i and including j characters (or all of them if j is not specified).
- string[255] Left ( coerce string[255] S, int i )
- Returns the i leftmost characters of s.
- string[255] Right ( coerce string[255] S, int i )
- Returns the i rightmost characters of s.
- string[255] Caps ( coerce string[255] S )
- Returns S converted to uppercase.
Vector functions:
- float Size( vector A )
- Returns the euclidean size of the vector (the square root of the sum of the components squared).
- vector Normal( vector A )
- Returns a vector of size 1.0, facing in the direction of the specified vector.
- Invert ( out vector X, out vector Y, out vector Z )
- Inverts a coordinate system specified by three axis vectors.
- vector VRand ( )
- Returns a uniformly distributed random vector.
- float Dist ( vector A, vector B )
- Returns the euclidean distance between two points.
- vector MirrorVectorByNormal( vector Vect, vector Normal )
- Mirrors a vector about a specified normal vector.
more on this topic in the Wiki: Global Function |
Prev Page: Legacy:UnrealScript Language Reference/States – Section 7 of 9 – Next Page: Legacy:UnrealScript Language Reference/Advanced Language Features