up:: [[Godot MOC]], [[Computing MOC]]
tags:: #note/develop #on/computing/gamedev #on/computing/languages
# GDScript
GDScript is a high-level programming language built for [[Godot MOC|Godot]]. It is [[Object Oriented Programming|object-oriented]], [[Imperative Programming|imperative]], and [[Gradual Typing|gradually typed]]. Its goal is to be optimized for and tightly integrated with the Godot Engine.
The language uses an indentation-based syntax similar to other languages like [[Python]].
GDScript is entirely independent from Python and is not based on it.
## Conventions
### Naming Conventions
#### Classes
Classes use PascalCase.
#### Variables and Functions
Variables and functions use snake_case.
#### Constants
Constants use ALL_CAPS.
#### Custom Signal Names
When naming a custom [[Godot Signals|signal]], use an action verb in the past tense. For example, `health_depleted`.
#### Callback Methods for Signal Connections
When connecting a [[Godot Signals|signal]] via code, a callback method will need to be passed to the signal's `connect()` method. By convention, this callback method should be named as `_on_nodeName_signalName` (for example, `_on_timer_timeout`).
When using [[C-Sharp|C#]] for this, the naming convention is `OnNodeNameSignalName` (for example, `OnTimerTimeout`).
## Quick Tips
> [!TIP] Placement of Member Variables in GDScript Files
> In GDScript, each file is implicitly a class. Member variables sit near the top of the script, after any `extends` lines, but before functions.
> [!TIP] Placement of Functions in GDScript Files
> Functions can be defined after they are used. For example, you can pass a callback function `on_timer_timeout` to a `connect()` method at the top of a file, while `on_timer_timeout` is defined at the bottom of the file.
> [!TIP] Editing Script Variables in the Editor Inspector
> Use the `@export` keyword on a variable to make it editable in the inspector.
> [!TIP] Shorthand for `get_node()`
> `
is shorthand for `get_node()` and returns the node at the relative path from the current node (or returns `null` if the node is not found).
## References
Juan Linietsky, Ariel Manzur, and Godot Community. “Godot Engine 4.2 Documentation.” Accessed February 29, 2024. [https://docs.godotengine.org/en/stable/index.html](https://docs.godotengine.org/en/stable/index.html).
Juan Linietsky, Ariel Manzur, and Godot Community. “GDScript Reference.” Accessed February 29, 2024. [https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/index.html](https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/index.html).