| Home Page | Recent Changes | Preferences

# Global Function

UT2003 :: Object (Methods)

The functions listed here are globally available in all classes. Due to UnrealScript's strict object-oriented approach, they're actually methods of the Object class.

Almost all of these functions are declared as native and final (see class syntax) and most of them are also static functions.

See vector, rotator and quaternion for functions on those variable types.

See Global Function (UT) for a list of global functions in UT.

## Integer Functions

int Rand (int Max) [static]
Returns a random number ranging from 0 to Max-1.
int Min (int A, int B) [static]
Returns the lower of the two values.
int Max (int A, int B) [static]
Returns the higher of the two values.
int Clamp (int V, int A, int B) [static]
If V is smaller than A, A is returned. If V is larger than B, B is returned. In any other case V is returned.

## Float Functions

float Abs (float A) [static]
Returns the absolute value (also known as the modulo) of A, usually written |A|. Eg: Abs(5) == Abs(-5) == 5.
float Sin (float A) [static]
Returns sine( A )
float Asin (float A) [static]
Inverse sine. Returns sin-1(A).
float Cos (float A) [static]
Returns cosine( A )
float Acos (float A) [static]
Inverse cosine. Returns cos-1(A).
float Tan (float A) [static]
Returns tan( A )
float Atan (float A, float B) [static]
Is this the function known as ATan2 in some languages? I want my ATan back!
float Exp (float A) [static]
Returns eA
float Loge (float A) [static]
Returns log(A), the natural logarithm.
float Sqrt (float A) [static]
Returns the square root of A.
float Square (float A) [static]
Returns A2.
float FRand ( )
Returns a random number between 0 and 1.
float FMin (float A, float B) [static]
Returns the lower of the two values.
float FMax (float A, float B) [static]
Returns the higher of the two values.
float FClamp (float V, float A, float B) [static]
If V is smaller than A, A is returned. If V is larger than B, B is returned. In any other case V is returned.
float Lerp (float Alpha, float A, float B) [static]
"Returns the linear interpolation between A and B."
The return value is calculated through something like this:
(B - A) * Alpha + A
float Smerp (float Alpha, float A, float B) [static]
Returns an Alpha-smooth nonlinear interpolation between A and B.
The return value seems to be calculated through something like this:
(-2 * (B - A) * Alpha ** 3) + (3 * (B - A) * Alpha ** 2) + A
float RandRange (float Min, float Max) [not native]
Returns a random number between Min and Max. This function is not static.
float Ceil (float A) [static]
Returns A rounded off to the next higher whole number, e.g. Ceil(1.8) returns 2, Ceil(-1.8) returns -1, etc. Ceil will always round up while typecasting float to int rounds up for negative numbers and down for positive numbers, i.e. int casts simply discard everything after the decimal point.
float Round (float A) [static]
Returns A rounded off to the nearest whole number, e.g. pass 1.05 and it returns 1.00, 5.5 will return 6.0 etc.

## String Functions

int Len (coerce string S) [static]
Returns the length of a string.
int InStr (coerce string S, coerce string t) [static]
If the string t is found inside S InStr returns the starting position with the first character of S being 0. If t is not found InStr returns -1.
string Mid ( coerce string S, int i, optional int j) [static]
Returns the middle part of S, starting at character i and including j characters (or all of them if j is not specified). Note: the 1st char has the number 0, this is diffrent then in visual basic, where the 1st char is 1.
string Left (coerce string S, int i) [static]
Returns the i leftmost characters of S.
string Right (coerce string S, int i) [static]
Returns the i rightmost characters of S.
string Caps (coerce string S) [static]
Returns S converted to uppercase.
string Chr (int i) [static]
Returns the character matchin the given ASCII code.
int Asc (string S) [static]
Returns the ASCII code of the first character in S.
bool Divide (coerce string Src, string Divider, out string LeftPart, out string RigthPart) [static]
Divides a string and returns the two parts.
int Split (coerce string Src, string Divider, out array<string> Parts) [static]
Splits a string iat the specified divider and returns the parts as a dynamic array of strings. If the input string starts with the given divider, the first element of the output array will be empty. Note: In early patch version of UT2003 this function was buggy. See El Muerte TDS/wUtils for a fix.

### UT2004 Specific

string Locs (coerce string S) [static]
Returns S converted to lowercase.
function string Repl ( coerce string Src, coerce string Match, coerce string With, optional bool bCaseSensitive ) [static]
Replaces all occurances of Match in string Src. Specify true for bCaseSensitive if matching should be case-sensitive.
function string Eval ( bool Condition, coerce string ResultIfTrue, coerce string ResultIfFalse ) [static]
Given boolean expression Condition, return string ResultIfTrue if the expression evaluates to true, otherwise return ResultIfFalse.

## General Functions

### InterpCurve Functions

(whatever that is)

float InterpCurveEval (InterpCurve curve, float input)
InterpCurveGetOutputRange (InterpCurve curve, out float min, out float max) [static]
InterpCurveGetInputDomain (InterpCurve curve, out float min, out float max) [static]

### Logging

Log (coerce string S, optional name Tag) [static]
Writes a line to the log file. The line begins with the Tag or "ScriptLog:" if Tag was not specified, followed by the log string.
The tags 'Error' and 'Warning' (and probably others, too) have a special meaning in Commandlets.
Warn (coerce string S) [static]
Same like Log, but the line starts with "ScriptWarning:" and contains information about the object, state and function that called Warn.
string Localize (string SectionName, string KeyName, string PackageName) [static]
Returns the string found in PackageName.int in the [SectionName] section. Logs an error if no localization for the specified string is found.

### State-Related

GotoState (optional name NewState, optional name Label)
Switches to a new state. State code execution begins at the specified label or at "Begin:" if Label is not specified.
Before the state is changed the old state's EndState function is called. After the state changed BeginState of the new state is called.
bool IsInState (name TestState)
Returns whether the object's current state is the one specified.
name GetStateName ( )
Returns the object's current state name.
BeginState ( ) [not native, not final]
This event is executed during GotoState right after the object switched to the new state. This function can be overridden in any state of any class.
EndState ( ) [not native, not final]
This event is executed during GotoState right before the object switches to the new state. This function can be overridden in any state of any class.

### Class Hierarchy

bool ClassIsChildOf (class TestClass, class ParentClass) [static]
Returns whether TestClass is a subclass of Parentclass.
bool IsA (name ClassName)
Returns whether the object's class is the specified class or a subclass. This function doesn't need a reference to the desired class, but just the class's name.

### Enabling / Disabling Functions

Enable (name ProbeFunc)
Enables a probe function.
Disable (name ProbeFunc)
Disables a probe function.

### Objects / Properties

string GetPropertyText (string PropName)
Returns the value of the specified property typecasted to string. This is useful when you don't want any dependencies to the package of an object, but still need to access its properties.
Usage: aString = anObject.GetPropertyText("PropertyName");
SetPropertyText (string PropName, string PropValue)
Assigns a value to the specified property of an object. Only use this for properties that can be typecasted from string.
Usage: anObject.SetPropertyString("PropertyName", "new value");
name GetEnum (Object E, int i) [static]
Returns the i-th element of the given enumeration, as in `GetEnum(enum'MyEnum', 2)` or an empty name of the specified index exceeds the number of elements in the enumeration.
Object DynamicLoadObject (string ObjectName, Class ObjectClass, optional bool MayFail) [static]
Loads and returns the specified object. If bMayFail is true no error will be logged.
Object FindObject (string ObjectName, class ObjectClass) [static]
SaveConfig ( )
Saves the current values of config and globalconfig variables of this object to the ini file and sets them as default values for the object's class.
StaticSaveConfig ( ) [static]
Saves the default values of config and globalconfig variables of this object's class to the ini file.
ResetConfig ( ) [static]
Resets the config and globalconfig variables of this object's class to the values stored in Default.ini or DefUser.ini.

#### UT2004 Specific

ClearConfig( optional string PropertyName )
Remove this object's section from the appropriate .ini file, and reload the script defaults for this object. If PropertyName is specified, only remove and reload that property, if found.
StaticClearConfig( optional string PropertyName ) [static]
Static version of ClearConfig().
ResetConfig( optional string PropertyName ) [static]
If object's class does not have a section in the default.ini or defuser.ini, ResetConfig() now performs ClearConfig(). Otherwise, functionality is same as before. If PropertyName is specified, only reset and reload that property, if found.
function array<string> GetPerObjectNames( string ININame ) [static]
Returns all section names that exist in the .ini file specified by ININame which correspond to PerObjectConfig classes.

## Other Functions

StopWatch (optional bool bStop) [static]
For script timing. Have done some testing, having StopWatch called on Tick() with different values for bStop. bStop=False seems to do nothing, not showing any HUD messages, output to stdout/err, or to logfile. First call with bStop=True prints text "UNICODE str: Time=%lf ms" to output, logs "Log: Unknown percent in UnUnix.cpp::wvsnprintf().", and crashes, whether there have been zero, one, or many previous calls with bStop=False. So far, none of this looks useful, but perhaps it needs to be used in a different context to work properly - on dedicated server, or in an Actor (my test was in an Interaction, in an "Instant Action" game).
StopWatch( false ); starts the stopwatch. StopWatch( true ); disables and resets the timer. When you stop the timer, a line will be printed in the log stating something like: Time=41.768ms. This is the time that the stopwatch was at when it was stopped. This makes it appear to be very much like clock.. but the log statement that shows the stop time is not what you can really do with StopWatch.
The magic of stopwatch is that when it is running it timestamps log entries. Each is stamped with the time elapsed since the timer was started. It is great for finding out the time taken throughout a function, without writing a veritable pile of clock and unclock statements, as well as adding temporary variables for them, and the works! See Optimization Techniques for more.
bool IsOnConsole ( )
For console specific stuff; the only reference to IsOnConsole() to be found is in 2136 of UT2K3 in a fragment found in PlayerController.uc. "Console" in this case refers to a game console, specifically the X-Box. Not the console dropped down and typed into.
bool IsSoaking ( )
For console specific stuff; the only references to IsSoaking() are to be found in 2136 of UT2K3 in Console.Initialized() and Console.KeyEvent().

## Related Topics

Foxpaw: How did you find out about the UT2004 stuff? Has some information about it been released?

Wormbo: You can safely assume that Evolution works on UT2004...

EntropicLqd: Cool, a billion bonus points and deep respect for putting some forward looking information on the Wiki. I guess those functions will be available in UT2003 once the patch is released to make UT2003 and UT2004 compatable.

Tarquin: BTW, I've change the heading levels but I don't know if I got it right

Pingz: Shouldn't this be renamed [Global Functions]??

Tarquin: singular names are easier to link to. "Foo is a Global Function"

Pingz: That makes some sense. IMO no matter what you do the title will never be right for every link situation, so why not put the burden on the linker: "See Foo in [Global Functions]?" or the more verbose "Foo is a global function. See [Global Functions]?."

Foxpaw: What's Evolution? (I don't mean the real kind. ) Also I agree that singular functions are better, you can always just say "Foo and bar are both Global Functions." Adding the s is much easier than using the pipe or using a separate sentance to indicate the link.

Wormbo: I think this page was named Global Functions before but was renamed for the very reason tarquin already stated.

Tarquin: Foxpaw and Wormbo are absolutely right. Pingz, when you see this, could you write it up into a FAQ item, or maybe a note on Guidelines On Page Creation. Then you can clean this bit up.