Skip to content

Latest commit

 

History

History
66 lines (41 loc) · 13.4 KB

native-types.md

File metadata and controls

66 lines (41 loc) · 13.4 KB
description
Built-in types available in the game runtime.

Built-in Types

Logical Types

KeywordTypeValues
KeywordTypeValues
BoolBoolean logic typetrue false

Integer Types

KeywordTypeRangeExample
KeywordTypeRangeExample
Int88-bit Signed Integer-128 to 127let a: Int8 = 161;
Uint88-bit Unsigned Integer0 to 255let a: Uint8 = 161u;
Int1616-bit Signed Integer-32,768 to 32,767let a: Int16 = 161;
Uint1616-bit Unsigned Integer0 to 65,535let a: Uint16 = 161u;
Int3232-bit Signed Integer−2,147,483,648 to 2,147,483,647let a: Int32 = 161;
Uint3232-bit Unsigned Integer0 to 4,294,967,295let a: Uint32 = 161u;
Int6464-bit Signed Integer−9,223,372,036,854,775,808 to 9,223,372,036,854,775,807let a: Int64 = 161l;
Uint6464-bit Unsigned Integer0 to 18,446,744,073,709,551,615let a: Uint64 = 161ul;

You can declare inline numbers using Cast<T>(value). It is useful for Int8/Uint8 and Int16/Uint16 for example:

// Fake function to use:
public static func UseNumber(a: Int8, ua: Uint8, b: Int16, ub: Uint16) -> Void;

// Use explicit cast
UseNumber(Cast<Int8>(127),
          Cast<Uint8>(255u),
          Cast<Int16>(32767),
          Cast<Uint16>(65535u));

Floating-Point Types

KeywordTypeRange
KeywordTypeRangeExample
Float32-bit Single-Precision6-9 significant decimal digits (more info)let a: Float = 3.141592;
Double64-bit Double-Precision15-17 significant decimal digits (more info)let a: Double = 3.141592653589793d;

Literal Types

KeywordTypePrefixExample
KeywordTypePrefixExample
StringMutable character string"Hello world"
CNameNon-mutable string constantnn"VehicleComponent"
ResRefResource reference pathrr"base\\anim_cooked.cookedanims"
TweakDBIDTweakDB Record IDtt"Items.RequiredItemStats"

String values are stored internally as a null-terminated character array, unfortunately the bytecode doesn't support accessing the individual characters as an array.

CName values are stored in-engine as a 64-bit hash key to a interned string pool. Class, function and field names are stored in the CName pool, so any methods that need a dynamic reference a scripted component will use a CName value.

ResRef values are similar to CName values, except they specifically refer to archive resource files and presumably use a separate optimized string pool. Unlike CName, ResRef doesn't have any defined operators.

TweakDBID is used as the primary key for all *_Record types stored in TweakDB, the engine's internal database.

Other Types

KeywordType
KeywordType
VariantA dynamic type that can store any other type

Operators

The RED4 scripting runtime implements most operators as native functions. Only the equals == and not equals != operators are implemented in bytecode. The redscript compiler provides a number of operator symbols as shorthand.

This table lists the available operators (in precedence block order) and what types support them.

TypeSymbolLogicalIntegerFloatStringCNameTweakDBID
TypeSymbolLogicalIntegerFloatStringCNameTweakDBID
Negate-----
Logical Not!----✓¹
Bitwise Not~-----
Multiplication*-✓²--
Division/----
Modulo%----
Addition+-✓³✓⁴✓⁴
Subtraction-----
Less Than<----
Less Than or Equal<=----
Greater Than>----
Greater Than or Equal>=----
Equals==✓⁵
Not Equals!=✓⁵
Logical And&&-----
Logical Or||-----
Bitwise And&-----
Bitwise Or|-----
Bitwise Xor^-----
Assign=
Assign Add+=--
Assign Subtract-=----
Assign Multiply*=----
Assign Divide/=----
Assign Bitwise And&=-----
Assign Bitwise Or|=-----

Notes

  1. The Logical Not ! operator for TweakDBID is overridden to return !TDBID.IsValid(a)

  2. Strings can be multiplied by an Int32 to repeat the string:

    public static func OperatorMultiply(a: String, count: Int32) -> String
  3. String addition is concatenation. There are native functions to allow most types can be concatenated with String

  4. CName and TweakDBID addition is concatenation (and presumably involves some kind of internal lookup to a known value)

  5. The redscript compiler doesn't currently support the == and != symbols for the CName type, use the Equals(a,b) and NotEquals(a,b) intrinsic functions for now.