Home » Godot Keywords

Keywords

These are the list of keyboards supported by the language. Keywords are reserved words (tokens), they cannot be used as identifiers. Operators (like in, not, and, or) and names of built-in types, as listed in the following sections, are also reserved.

The keyboard is defined in the GDScript tokenizer which are given below:

Keyword Description
If See if/else/elif.
else See if/else/elif.
elif See if/else/elif.
For See for.
do Reserved for future implementation of do…while loops.
match See match.
while See while.
case It booked for the next applications.
switch It reserved for future implementation.
break It exits the execution of the current for or while loop.
continue It skips immediately skips to the next iteration of for or while loop.
pass It used where a statement is required syntactically, but the execution of code is undesired, e.g., in empty functions.
return Returns a value form a service.
class Defines a class.
is Tests whether a variable extends with the current quality.
extends Explains what class to reach with the current class.
self This refers to the current class instance.
tool It executes the script in the editor.
signal It defines a sign.
func It represents a function.
static It defines a static function, and Static member variables are not allowed.
const Defines a constant.
enum It establishes an enum.
var It represents a variable.
on ready Initializes variables once the Node the script is attached to and its children are modifiable in the editor.
export It saves a variable along with the resource it’s connected to and makes it visible and modifiable in the editor.
set get It defines setter and getter functions for a variable.
preload Preloads a class or variable.
breakpoint Editor helper for debugger breakpoints.
yield Co-routine support.
assert Asserts a condition, logs error on failure. Ignored in non-debug builds.
remote Networking RPC annotation.
master Networking RPC annotation.
slave Networking RPC annotation.
sync Networking RPC annotation.
TAU TAU constant.
INF Infinity is constant. Used for comparisons.
NAN NAN (not a number) constant. Used for comparisons.
PI PI constant.

Operators

The following is the list of supported operators and its precedence.

Operator Description
x[index] Subscription, Highest priority
x.attribute Attribute reference
is Instance Type Checker
~ Bitwise NOT
-x Negative
*,/,% Multiplication/Division/Remainder
Note: The result of these operations depends upon the types of the operands. If both are Integers, then the result will be an Integer. That means 1/10 returns 0 instead of 0.1. If at least one of the operands is a float, then the result is a float: float (1)/10 or 1.0/10 return both 0.1.
+,- Addition/Subtraction
<<,>> Bit shifting
& Bitwise AND
^ Bitwise XOR
| Bitwise OR
<,>,==,!=,>=,<= Comparisons
in Content Test
!, not Boolean NOT
and,&& Boolean AND
or,|| Boolean OR
If x else Ternary if/else
=,+=,-=,*=,/=,%=,&=,|= Assignment, Lowest Priority

Literals

Literal Type
45 Base 10 integer
0x8F51 Base 16 (hex) integer
3.14,58.1e-10 Floating-point number(real)
“Hello”,” Hi” Strings
“”” Hello””” Multiline string
@” Node/Label” Node path or StringName

Comments

Anything from a #(hash) to the end of the line is ignored and considered as a comment.

Multi-line comments can be created using “”” (three quotes in a row) at the beginning and end of a block of text. Note that this creates a string; therefore, it will not be stripped away when the script is compiled.

Built-in types

Built-in types are stack-allocated, and they are passed as values. This means a copy is created on each assignment or when it was moving them as arguments to functions. The only exceptions are Array and Dictionaries, which are given by reference, so they are shared. (Not PoolArray like PoolByteArray though, those are passed as values too, so consider this when deciding which to use!)

Basic built-in types

A variable in GDScript can be assigned to several built-in types.

null

It is an empty data type that contains no information and cannot be assigned any other value.

Bool

The Boolean data type only contains true or false.

Int

This data type can contain only integer numbers (both negative and positive).

float

It is used to provide a floating-point value (real numbers).

String

A sequence of characters in Unicode format. Strings can contain the standard C escape sequences. GDScript supports format strings printf functionality.

Vector built-in types

Vector2

2D vector type containing x and y fields. It can also be accessed as an array.

Rect2

2D vector type containing two vectors fields: position and size. Alternatively contains an end field, which is position+size.

Vector3

3D vector type containing x, y, and z fields. This can also be accessed as an array.

Transfrom2D

In 2D, transforms 3×2 matrix is used.

Plane

3D plane type in the normalized form that contains a standard vector field and a d scalar distance.

Quat

Quaternion is a data type used for representing a 3D rotation. It is useful for interpolating rotations.

AABB

The axis-aligned bounding box (or 3D box) contains two vectors fields: position and size. Alternatively contains an end field, which is positive + size.

Basis

3×3 matrix used for 3D rotation and scale. It contains three vector fields (x, y, and z) and can also be accessed as an array of 3D vectors.

Transform

3D transform contains a basis field basis and a Vector3 field origin.

Engine build-in types

  • Color

The data type contains r, g, b, and fields. It can also be accessed as h, s, and v for hue/saturation/value.

  • NodePath

Compiled path to a node used mainly in the scene system. It can be easily assigned to and from a string.

  • RID

Resource ID (RID). Servers use generic RIDs to reference opaque data.

  • Object

Base class for anything that is not a built-in type.

Container built-in types

Array

Arrays are indexed starting form index 0. Starting with Godot 2.1, indices may be negative like in python, to count from the end. Generic sequence of arbitrary objects types, including other arrays or dictionaries. The array can resize dynamically.

GDScript arrays are allotted linearly in memory for speed. Large arrays, which are more than tens of thousands of elements) may, however, cause memory fragmentation. If it is a concern, particular types of arrays are available. These only accept a single data type. They avoid memory fragmentation and also use less memory but are atomic and tend to run slower than generic arrays. They are recommended to use for large data sets.

  • PoolByteArray: An array of bytes (integer from 0 to 255).
  • PoolIntArray: An array of integers.
  • PoolStringArray: An array of strings.
  • PoolcolorArray: An array of Color objects.
  • PoolRealArray: An array of
  • PoolVector2Array: An array of Vector2
  • PoolVector3Array: An array of Vector3

Dictionary

Associative container which contains values referenced by unique keys.

Lua-style table syntax is also supported. Lua-style uses = instead of: and does not use quotes to mark string keys (making for slightly less to write).Keys are written in this form cannot start with a digit.

To add a key to an existing dictionary, access it like an existing key and assign to it:

Data

Variables

Variables can exist as class members or local to functions. They are created with the var keyboard and may, optionally, be assigned a value upon initialization.

Constants

Constants are similar to the variables, but must be constants or constant expressions and must be assigned on initialization.

Enums

Enums are a shorthand for constants and are pretty useful if we want to assign consecutive integers to some constant.

If we pass a name to the enum, it also put all the values inside a constant dictionary of the name.

Functions

Functions belong to a class always. The scope priority for variable look-up: local-class member-global. The self-variable is always available and is provided as an option for accessing class members, but is not always required (and cannot be sent as the function’s first argument, unlike python).

It can return at any point. The default return value is null.


You may also like