Types

ZScript has several categories of types: Integer types, floating-point (fractional) types, strings, vectors, names, classes, et al. There are a wide variety of ways to use these types, as well as a wide variety of places they are used.

Types determine what kind of value an object stores, how it acts within an expression, etc. All objects, constants and enumerations have a type. Argument lists use types to ensure a function is used properly.

Most basic types have methods attached to them, and both integer and floating-point type names have symbols accessible from them. See the API section for more information.

There is one additional type, void, which resolves to None. If a class is named None, void objects will actually work. It is unknown why this exists, and is likely an implementation error.

Type

Numeric Types

Numeric types include integer and floating-point numbers.

NumericType

Integer Types

Integer types are basic integral numbers. They include:

TypeArgumentBitsLowest valueHighest value
intOK32-2,147,483,6482,147,483,647
uintOK3204,294,967,296
int16No16-32,76832,767
uint16No16065,535
int8No8-128127
uint8No80255

Some types have aliases as well:

TypeAlias of
sbyteint8
byteuint8
shortint16
ushortuint16
IntegerType
  • byte
  • int16
  • int8
  • int
  • sbyte
  • short
  • uint16
  • uint8
  • uint
  • ushort

Floating-Point Types

Floating-point types hold exponents, generally represented as regular decimal numbers with a fraction. There are four such types available to ZScript.

Note that float32 is not implemented correctly, and thus is unusable. Additionally, float is 32 bits as a member variable, but 64 bits elsewhere.

TypeArgumentBits
doubleOK64
floatOK32 or 64
float64OK64
float32No32
FloatingPointType
  • double
  • float
  • float64
  • float32

String Types

The string type is a mutable, garbage-collected string reference type. Strings are not structures or classes, however there are methods attached to the type, detailed in the API section.

Strings are usable as arguments.

StringType

string

Name Types

The name type is an indexed string. While their contents are the same as a string, their actual value is merely an integer which can be compared far quicker than a string. Names are used for many internal purposes such as damage type names. Strings are implicitly cast to names.

Names can be converted to int with an explicit cast, and the negative of int(name()) may be used to create an integer representation of a string usable by action specials, most prominently Acs_NamedExecute.

Names are usable as arguments.

NameType

name

Boolean Types

Booleans hold one of two values: true or false.

Booleans are usable as arguments.

BooleanType

bool

Integer-like Reference Types

There are multiple types that act similarly to integers, but are distinct types.

Integer-like references are usable as arguments.

IntegerLikeReferenceType
  • spriteId
  • textureId

String-like Reference Types

There are multiple types that act similarly to strings, but are distinct types. Strings will implicitly convert to these types.

String-like references are usable as arguments.

StringLikeReferenceType
  • sound
  • stateLabel

Color Types

The color type can be converted from a string using the X11RGB lump or a hex color in the format #RRGGBB or #RGB.

Colors are usable as arguments.

ColorType

color

Let Types

The let type automatically determines the type of a variable by its initializer. This type may only be used in LocalVariableStatements.

LetType

let

Vector Types

There are two vector types in ZScript, vector2 and vector3, which hold two and three members, respectively. Their members can be accessed through X, Y, and for vector3, Z. vector3 can additionally get the X and Y components as a vector2 with Xy.

Vectors can use many operators and even have special ones to themselves. See the Expressions and Operators section for more information.

Vectors are usable as arguments.

VectorType
  • vector2
  • vector3

Fixed Array Types

Fixed arrays hold size number of Type elements, which can be accessed with the array access operator.

Multi-dimensional arrays are also supported. The dimensions of multi-dimensional arrays will be backwards (right to left instead of left to right) if the version of the archive is lower than 3.7.2.

Note that this kind of type can also be declared in variable names themselves.

Fixed arrays are not usable as arguments.

FixedArrayType

Identifier ([ ConstantExpression? ])+

Dynamic Array Types

Dynamic arrays hold an arbitrary number of Type elements, which can be accessed with the array access operator.

Dynamic arrays do not have their lifetime scoped to their current block, so the following code will result in an array with 5 elements:

for(int i = 0; i < 5; i++)
{
	array<int> a;
	a.Push(0);
}

Dynamic arrays also cannot store most types. Here is a list of types they can hold:

  • Class Instance
  • Class Reference
  • double
  • float
  • int16
  • int8
  • int
  • string
  • uint16
  • uint8
  • uint

Dynamic arrays are usable as arguments.

DynamicArrayType

array < Type >

Map Types

Maps are not yet implemented, but exist in syntax.

Maps are not usable as arguments.

MapType

map < Type , Type >

Class Reference Types

Class references are used to describe a concrete type rather than an object. They can be restrained to descendants of a type. Strings are implicitly cast to class references.

Class references are usable as arguments.

ClassReferenceType
  • class
  • class < Type >

Native Pointer Types

Types prefixed with @ are native pointers to objects, as opposed to objects placed directly in the structure's data. This is not usable in user code and will not be exposed by the API documentation as its usage is not relevant. There is also a voidPtr type that is usable in user code, which refers to a real memory address.

Native pointers are usable as arguments.

NativePointerType

Read-only Types

A read-only type, as its name implies, may only be read from, and is effectively immutable. Do note that this is separate from the member declaration flag, and in member declarations readOnly int and readOnly<int> are equivalent, however elsewhere this is not the case.

Read-only objects are usable as arguments.

ReadOnlyType

readOnly < Type >

Instance Types

Any other identifier used as a type will resolve to a class, structure or enumeration instance.

An instance type that is nested within another type could be accessed through a similar syntax to member access according to the grammar, however, this won't actually work, and only the first identifier will be used.

TypeArgument
Class InstanceOK
Enumeration InstanceOK
Native Structure InstanceOK
Normal Structure InstanceNo
InstanceType

Variable Names

Variable names can have an array's size on them, instead of on the type, or none at all for normal variables.

VariableType

Identifier ([ ConstantExpression? ])*