# Guide to the Godot game engine/Programming/GDScript/Keywords

Guide to the Godot game engine
<-- Global scope Keywords If statements-->
Skip to bottom

## Keywords

Keywords in Godot are special words used for GDScript. Unfortunately, some of them are not recorded in Godot's class documentation in much detail.

### await

The await keyword will wait for the passed signal to be emit.

### break

The break keyword ends a looping piece of code. Useful for "forever" loops:
This ends the loop after 15 runs of the code.

### continue

The continue keyword is used inside loops. Similar to break, continue skips a single run at the loop. Like breaking it, but instead of ending the whole loop, it only skips the single iteration.
The above runs 5 times. Num is 1, 2, 3, 4 then 5. If num is 4, it "continues" the loop. Otherwise it prints. So 4 is not printed, but 1, 2, 3 and 5 are.

### const

The const keyword can be used in place of var to create a constant, a value that cannot change.
Unlike variables, constants can be used in static functions.

### enum

The enum keyword is similar to making integer constants.
The code above is a snippet of code from an image editor I once made in Godot. It shows the possible draw modes, like line and fill, as named ints for easier code debugging.

### @export

Not to be confused with exporting. The @export keyword is a very powerful keyword.
It allows editing the value in the Inspector dock, and it saves changes per-instance.
For a basic one, try @export var max_health:int.
You can even use templates and ranges:

### extends

The extends keyword tells Godot that a script inherits the properties of the given Object.
It must be at the very top of a script. Only tool can go before it.

### for

The for keyword runs the indented block of code after it for every item from a given value.

### in

Often used inside if statements. It evaluates as true if the value before it is inside the value after it. It can check:
* If a value is in an Array
* If a key is in a Dictionary
* If a string of text contains another string of text
* If an Object contains a property or constant of the same name
Among other things. "h" in "Hello" would be false. "Hello" does not have a lowercase "h" in it. If you want case insensitive search, call to_lower on both values to convert every letter to lowercase (or to_upper for uppercase - all capitals).

### is

Often used in if statements. It checks if the value before it is of the type after it.

### load

Okay, load is technically described in global scope. However, it is very much defined as a keyword, so it would make no sense if it were not here.
It loads a file from your FileSystem when called. It takes a single argument: a file path.
File paths must be relative to your project folder or player save folder and not lead outside!
Valid examples:
res leads to your project folder. user leads to the player's save folder. This is typically %appdata%/roaming/godot/app_userdata/<project_name> unless the ProjectSetting Config/Use Custom User Dir and Config/Custom User Dir Name are set, in which case it's %appdata%/roaming/<ProjectSettings:Config/Custom User Dir Name>.

### master

The master keyword is part of a series 5 multiplayer keywords. It makes it so only the "master" calls a function if used.
You don't want to call this on a puppet to help prevent bugs.

### @onready

The @onready keyword goes before the var keyword. It allows using a dynamic number that or getting a node using a nodepath, and is set before the _ready function call.

### pass

The pass keyword is used as a blank line of code. Use it after an "if" statement or "for" statement or after a function declaration to count as a "block of code" (to remove the error) without doing anything. This is called an "empty" if statement or a "stub function".

### preload

See load. The file can be relative to the script that calls it or "res". The resource is loaded when the script is, preventing stalls during the running game. However, files must exist or there will be an error, and the path must be constant (i.e: not changeable).
res://game/game.gd:
or:

### puppet

The puppet keyword is one of a series of 5 multiplayer keywords. Use it before "func" but after "remote". It makes a function only call to non-masters.
You don't want to call this to the master to stop players cheating.

### remote

Use the remote keyword before the "func" keyword to allow a function to be called remotely by other peers in multiplayer when calling "rpc", "rpc_id", "rpc_unreliable" or "rpc_unreliable_id". Beware of cheating and security threats when doing this!
See puppet and master for more info. Use remotesync to call the function locally as well as via the network.
WARNING: Malicious hackers can use your game to retrieve or delete data, or players can cheat, if you do not add checks to stop them. Don't ever add remote to functions that delete or create files unless you know what you're doing.

### remotesync

See remote. This keyword also calls a function locally instead of only calling them over the network. Good for telling other peers as well as the master that the character has jumped.

### return

The return keyword is used to end the function. For functions that are called and "return" a value, the return keyword is where to go.
It also ends the function call, so can be used in an if statements to skip the rest of the function. It does not require a return value, and by default returns null.

### static

Usually, to call an Object's function, you need an instance of it. If you use the static keyword before the "func" keyword, you'll be able to call it from a non-instance. However, you can only use other static functions or those in global scope. You cannot use member variables.
In the following example, Weapon is a custom Resource.

#### Weapon.gd

Weapon.new( ).get_damage( ) becomes Weapon.get_damage( ), saving memory and CPU resources if you were to want to find a value.

### @tool

The @tool keyword tells Godot that a script runs in the editor. These sorts of scripts are commonly referred too as tool scripts. It won't run if the script is only open in the Script edit screen. It must be attached to a node in the scene, or a node with the script must be in the editor.
It must always be placed before the extends keyword. It can be placed on the same line as the extends if you find it more convenient.
If you have a tool script, scripts that it inherits and scripts that inherit it won't run, unless they are also tool scripts. All nodes themselves run in the editor, but only if placed into it's interface with editor plugins.
See also: editor plugins (and the plugins chapter), very powerful things.

### var

The var keyword creates a variable. They are automatically freed from memory when they leave the scope (an indented block of code unindents, for example.)

### while

The while keyword runs the indented block of code after it until the if-statement after it is no-longer true. It won't run if it starts as false.
GDScript
* Global scope
* Keywords
* If statements
* If conditions
* Data types
* Manipulate the SceneTree
* Making nodes
* Tips and Tricks