AngelScript quick reference

Types, operators, handles and other basics of the language at a glance.

Statements

  • if / else, while, do … while and for (int i = 0; i < 10; i++) work like in C++, with break and continue.
  • switch works only with integers, each case needs a break unless it should continue with the next one.
  • auto declares a variable of the type of its initial value, const one that can't be changed.
  • Comments are // line and /* block */.
  • Calling a method of a null handle, indexing out of range or dividing an integer by zero raises a script exception, which stops the running function.

Operators

OperatorsMeaning
+ - * / %Arithmetic. Dividing two integers drops the remainder, % gives the remainder, also of floating-point numbers.
**Power, 2 ** 10 is 1024.
++ --Increment and decrement, either before the value is used (++i) or after it (i++).
== != < > <= >=Comparison.
&& || ^^ !Logical and, or, exclusive or and not, also written as and, or, xor and not. && and || skip the right side when the left side decides the result.
& | ^ ~Bitwise and, or, exclusive or and not.
<< >> >>>Bit shifts. >> fills with zeros even for negative numbers, >>> keeps the sign.
= += -= *= /= %= **= &= |= ^= <<= >>= >>>=Assignment, a += b is the same as a = a + b.
? :Conditional, a > b ? a : b is the larger of the two.
@ is !isHandles, see Handles and references.
. [] () ::Member, index, call and scope, NS::name is a name in a namespace and ::name one in the global namespace.

Operators have the usual precedence, for example * before + and comparisons before &&. Parentheses make the order clear when unsure.

Primitive types

Types built into the language. Values of these types are always copied when assigned or passed by value.

TypeSize (bytes)Values
voidNo value. Used only as the return type of functions that don't return anything.
bool1true or false.
int81Signed integer from -128 to 127.
int162Signed integer from -32 768 to 32 767.
int, int324Signed integer from -2 147 483 648 to 2 147 483 647. The usual integer type, whole number literals such as 42 are of this type. int32 is the same type.
int648Signed integer from -9 223 372 036 854 775 808 to 9 223 372 036 854 775 807.
uint81Unsigned integer from 0 to 255.
uint162Unsigned integer from 0 to 65 535.
uint, uint324Unsigned integer from 0 to 4 294 967 295. uint32 is the same type.
uint648Unsigned integer from 0 to 18 446 744 073 709 551 615.
float4Floating-point number with about 7 significant digits. Literals with the f suffix, such as 1.5f, are of this type.
double8Floating-point number with about 15 significant digits. Literals with a decimal point and no suffix, such as 1.5, are of this type.
autoNot a type of its own, a variable declared as auto takes the type of the value it's initialized with, e.g. auto count = 5; declares an int.
?A value of any type. Only functions of the application use it, for parameters that accept anything, such as const ?&in.

Literals

  • Integers: 42, hexadecimal 0x2A, binary 0b101010 and octal 0o52.
  • Floating-point numbers: 1.5 and 1e3 are double, 1.5f is float.
  • true and false, and null for a handle with no object.
  • Strings: "text" with escape sequences such as \n, \t, \", \\ and \u00E9. Text between """ can span more lines and has no escape sequences. The string type itself is provided by the application.

Conversions

Numbers convert between each other implicitly. Converting to a smaller type, between signed and unsigned types or from a floating-point number to an integer may lose a part of the value, the compiler warns about some of these cases. A floating-point number converted to an integer is truncated towards zero. Use an explicit conversion such as int(value) to make the intent clear.

A handle converts to a handle of a base class or an interface implicitly. The other way, cast<T>(handle) gives a handle of type T, or null if the object isn't of that type.

Handles and references

Other types are either value types, copied just like the primitive types, or reference types, whose objects are reached through handles. In declarations the following marks appear:

  • @ — a handle, a reference to an object of a reference type. Several handles may refer to the same object and the object lives as long as some handle refers to it, unless the application owns it. A handle with no object is null. @a = @b makes a refer to the object of b, while a = b copies the object itself. a is b tells whether both refer to the same object, a !is null whether there's any.
  • &in — a parameter the function only reads, usually together with const. The function may get a copy of the value.
  • &out — a parameter the function writes a result to, the variable passed in gets the value when the function returns.
  • &inout or & — a reference to the original variable, which the function can read and change.
  • const — the value can't be changed through this variable or parameter.

Some types of the application don't allow handles at all, a script then only uses the instances the application provides. Such types are marked no handles, value types are marked by value.