Variable Type
This page lists the variable types in UnrealScript. For details on declaring variables, see Variable Syntax.
Simple Types
bool
Boolean values: True, False
Initial value: False
Boolean values can't be used for arrays or as out parameters of functions.
int
Numbers from -2147483648 to 2147483647.
Initial value: 0
byte
Numbers from 0 to 255.
Initial value: 0
Assigning a number that exceeds this range will wrap it at the boundaries (so setting a byte variable to 256 will actually set it to 0).
float
Floating point numbers (single precision with a 24 bit mantissa).
Initial value: 0
Maximum precision error free: 223 = 8388608
string
Any number of characters (including zero) enclosed in double quotes.
Initial value: Empty string ""
- Escape characters by prefixing them with a backslash:
"
for literal double quotes in a string andfor literal backslashes.
- For a newline character use the
Chr(13)
function call (n
is just a (needlessly) escapedn
) - Some Unreal Tournament classes have support for the
n
escape on UnrealScript level, for instance UWindowDynamicTextArea? (which is, among other things, used to display the weapon description for TournamentWeapon, so you can usen
– escaped asn
in the Default properties block of a .UC file – to create line breaks in such a description).
name
An identifier enclosed in single quotes.
Initial value: 'None'
The identifier may only contain letters, numbers and underscores. Names are not case-sensitive, so 'RedeemerDeath' and 'rEdEeMeRdEaTh' are basically the same thing, but the first appearance of the name in UnrealScript code will be used when converting it to string. (e.g. for logging)
Vector, rotator, etc
Other apparent variable types such as vector, rotator, color, etc. are in fact built-in structs, enums or Objects.
Pointer
There seems to be a new built-in type pointer
which is used instead of int
for C++ pointers as of build 2166.
Structs
struct modifiers StructName { variable declaration 1; variable declaration 2; ... };
Variable declaration within struct declaration uses the same syntax as class variables. All elements of the struct are initialized with their corresponding null values.
Structs can't be declared within functions.
Like variable declarations, struct declarations can have modifiers. The following struct modifiers have been spotted in UT2003 code:
- native
- export
The struct's name can be used as variable type within variable and function declarations. A struct declaration can also be used directly as the type of a variable, e.g.:
var VariableModifiers struct StructModifiers StructName { variable declaration 1; variable declaration 2; ... } name, name, ...;
There are some built-in structs in UnrealScript like vector, rotator and color. (all declared in Object)
Also you can build a new struct on the base of an old struct.
In object for example:
// A point or direction vector in 3d space. struct Vector { var() config float X, Y, Z; }; // A plane definition in 3d space. struct Plane extends Vector { var() config float W; };
So the Plane will get the X,Y,Z from Vector, but will also includes it's own W.
Enums
enum EnumName { EnumValue1, EnumValue2, ... };
Enums can be declared within the variable's type like structs.
var enum EnumName { EnumValue1, EnumValue2, ... } name, name, ...;
Enums are internally handled as byte variables and show some strange behavior when you try to typecast them. The initial value of an enum is its first element.
There are some built-in enumerations in UnrealScript like the ERole enumeration used in the Role and RemoteRole variables declared in the Actor class.
If you want to know the number of items in the enum use EnumCount(ENumName).
To get the name representation of an enum value, use GetEnum(), defined in Object. It takes two parameters - the enum object, and an int corresponding to the value. The expected type for the object parameter is the name of the enum, explicitly casted to an enum. ex:
log("Logging my Role and RemoteRole - Role:" $ GetEnum( enum'ENetRole', Role ) @ "RemoteRole:" $ GetEnum( enum'ENetRole', RemoteRole ));
El Muerte TDS: don't know if this always has been like this, but in UT2003 I have to do the following to get the number of elements in a enum:
EnumName.EnumCount
Objects
Specify the name of the object as the type of the variable, e.g. Actor, Sound or UWindowList.
The initial value of Object variables is None
. Unlike for name properties, this None is not enclosed in single quotes.
Sobiwan: I thought those examples listed were classes. If that is the case, what is an object?
GRAF1K: Objects are classes, just like weapons are actors. In other words:
class Object extends Class;
The unrealscript is just a joke, but you get the point.
Wormbo: Actually the datatype Class is a subclass of Object in UnrealScript. Classes in general are descriptions of a type of objects. Some objects are Actors, others are Sounds or Textures and there are also Class objects. You use them very often in default properties or in code, e.g. Texture'Engine.DefaultTexture', Sound'WeaponSounds.ExplosionSounds.Boom123' or class'xGame.xPawn'. If you opened the properties of e.g. a weapon during the game and checked its Owner property, you'd probably see something like xPawn'CTF-SomeWeirdMap.xPawn9' as the value.
Sobiwan: Considering classes are holders for variables and methods (functions) and classes are considered objects in OOP-speak, I still dont see the difference in passing a variable as an Object vs Class type. They are the same thing, no?
Wormbo: Objects and classes are anything else than "the same". It's like comparing a house and a booklet describing how to build a house. In the case of the four examples above Texture'Engine.DefaultTexture' would be an object of class 'Texture', Sound'WeaponSounds.ExplosionSounds.Boom123' is an object of class 'Sound', xPawn'CTF-SomeWeirdMap.xPawn9' is an object of class 'xPawn' and finally class'xGame.xPawn' is an object of class 'Class'. In UnrealScript classes can be used like objects, that might differ greatly in other languages. Deep down in the engine even functions, enums, structs and variables are objects, for enums this can be seen in the GetEnum function mentioned above, but I wouldn't worry about that too much. For now I'd suggest thinking of classes as templates for new objects. Classes define the methods and properties of objects instanciated from them and also specify default values for the properties.
Sobiwan: Let me see if I got this straight: if its not an operator (ie +-) or conditioner (shampoo, er, if then else), then its an object. Is that right?
Classes
Either just specify class
as the type or use a special class like class<Actor>
. You can also use every other class name instead of "Actor". For obvious reasons class<Object>
has the same meaning as just class
. Classes are just a special kind of Object reference, so their initial value also is None
.
If you wish to find out whether an object is of the same type as a class type then you can use the Name property of the Class object you have.
var class<Weapon> biggerGun; .. if ( someObject.IsA( biggerGun.Name ) ) { // Code here } .. default properties { biggerGun=Class'Botpack.WarHeadLauncher' }