Skip to content

NativeTypes

Reece Sheppard edited this page Jun 21, 2021 · 3 revisions

Native Types

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

Logical Types

Keyword Type Values
Bool Boolean logic type true or false

Operators

Supported operators, in precedence order:

Symbol Function
&& func OperatorLogicAnd(a: Bool, b: Bool) -> Bool
|| func OperatorLogicOr(a: Bool, b: Bool) -> Bool
! func OperatorLogicNot(a: Bool) -> Bool

Integer Types

Keyword Type Range
Int32 32-bit Signed Integer −2,147,483,648 to 2,147,483,647
Int64 64-bit Signed Integer −9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
Uint32 32-bit Unsigned Integer 0 to 4,294,967,295
Uint64 64-bit Unsigned Integer 0 to 18,446,744,073,709,551,615

Operators

Supported operators for all of the above types (substituting Int32), in precedence order:

Symbol Function
- func OperatorNeg(a: Int32) -> Int32
~ func OperatorBitNot(a: Int32) -> Int32 (bitwise)
* func OperatorMultiply(a: Int32, b: Int32) -> Int32
/ func OperatorDivide(a: Int32, b: Int32) -> Int32
% func OperatorModulo(a: Int32, b: Int32) -> Int32
+ func OperatorAdd(a: Int32, b: Int32) -> Int32
- func OperatorSubtract(a: Int32, b: Int32) -> Int32
< func OperatorLess(a: Int32, b: Int32) -> Bool
<= func OperatorLessEqual(a: Int32, b: Int32) -> Bool
> func OperatorGreater(a: Int32, b: Int32) -> Bool
>= func OperatorGreaterEqual(a: Int32, b: Int32) -> Bool
& func OperatorAnd(a: Int32, b: Int32) -> Int32 (bitwise)
| func OperatorOr(a: Int32, b: Int32) -> Int32 (bitwise)
^ func OperatorXor(a: Int32, b: Int32) -> Int32 (bitwise)
+= func OperatorAssignAdd(out a: Int32, b: Int32) -> Int32
-= func OperatorAssignSubtract(out a: Int32, b: Int32) -> Int32
*= func OperatorAssignMultiply(out a: Int32, b: Int32) -> Int32
/= func OperatorAssignDivide(out a: Int32, b: Int32) -> Int32
func OperatorAssignAnd(out a: Int32, b: Int32) -> Int32
func OperatorAssignOr(out a: Int32, b: Int32) -> Int32

Floating-Point Types

Keyword Type Range
Float 32-bit Single-Precision 6-9 significant decimal digits (more info)
Double 64-bit Double-Precision 15-17 significant decimal digits (more info)

Operators

Supported operators for all of the above types (substituting Float), in precedence order:

Symbol Function
- func OperatorNeg(a: Float) -> Float
* func OperatorMultiply(a: Float, b: Float) -> Float
/ func OperatorDivide(a: Float, b: Float) -> Float
% func OperatorModulo(a: Float, b: Float) -> Float
+ func OperatorAdd(a: Float, b: Float) -> Float
- func OperatorSubtract(a: Float, b: Float) -> Float
< func OperatorLess(a: Float, b: Float) -> Bool
<= func OperatorLessEqual(a: Float, b: Float) -> Bool
> func OperatorGreater(a: Float, b: Float) -> Bool
>= func OperatorGreaterEqual(a: Float, b: Float) -> Bool
+= func OperatorAssignAdd(out a: Float, b: Float) -> Float
-= func OperatorAssignSubtract(out a: Float, b: Float) -> Float
*= func OperatorAssignMultiply(out a: Float, b: Float) -> Float
/= func OperatorAssignDivide(out a: Float, b: Float) -> Float

Literal Types

Keyword Type Prefix Example
String Mutable character string "Hello world"
CName Non-mutable character string n n"VehicleComponent"
ResRef Resource reference path r r"base\\movies\\misc\\distraction_generic.bk2"
TweakDBID TweakDB Record ID t t"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.

Clone this wiki locally