GDScript Crash Course Notes
Notes on getting started quickly with Godot’s native programming language — GDScript
This article will be updated long-term (last updated 2026.3.30)
Preamble
A few days ago I published my Godot study notes, with no反响. If they were explosively popular at this stage, that would be abnormal.
Given the importance of programming languages, I’m opening another article here as a GDScript study log.
The video is divided into three parts. For ease of reference, I’ll mark points as “前中后言”.
This article is based on Brackeys’ GDScript快速上手 tutorial. Here’s the Bilibili link.
Helloworld
A new script will contain two basic functions. I’ve already written about these two functions in my Godot notes, so I won’t repeat them here.
Use the print keyword to output content:
1 | print("helloworld") |
Syntax
There are only a few things to know from this part of the video:
- Indentation determines code structure
- Case sensitivity
Indentation indicates归属, as shown in the code:
1 | func _ready() -> void: |
Modifying Nodes 1.0
Just outputting to the console is boring. Nobody playing a game wants to look at your console.
As mentioned in the previous article, nodes are an important part of Godot. We can modify node properties through references in scripts.
There are two ways to bind a node. The first is the manual reference syntax mentioned in the previous article.
The second is to drag the node directly from the node panel into the IDE, which will auto-generate the statement.
A typical reference format looks like this:
1 | $Label.modulate = Color.GREEN # referenced_node.property = modified_property |
Key Binding
- Create an input map event
First, open Project - Project Settings - Input Map.
Create a new mapping, then press the plus sign to bind a key. Following the example from the video: Create an event named my_action that changes the Label’s color when the spacebar is pressed.
- Call the input map event in a script
The system function for input binding is the _input function, formatted as follows:
1 | func _input(event): |
Variables 1.0
A variable is a property — the name is self-explanatory, so I won’t elaborate.
The syntax for defining a variable is as follows:
1 | var varname = 20 |
Variables can be changed using operators:
1 | varname = 20 # direct assignment |
Reference the key binding section above to change variable values when performing corresponding actions.
If Statements
Standard Format
Seriously, this overlaps heavily with other languages, so I’ll just write the format:
1 | if varname <= 0: |
If you’re a complete beginner who stumbled onto this by accident: in a nutshell, if the condition after if is met, then the corresponding action is executed.
Condition Format
Both conditions must be met, or at least one:
1 | if varname <= 0 and value = 1: |
else/elif Format
The “then” in “if…then…”:
1 | if var > 0: |
Comments
1 | # Hash symbol, explanation complete |
Variables 2.0
A variable declared inside a function can only be used within that function. But if declared in a broader scope, it can be used throughout the entire script.
The former is called a local variable, the latter a global variable.
Common Data Types
GDScript is a dynamically typed language. Unlike statically typed languages, you don’t need to declare the variable type before assigning a value, and types can be converted directly.
int: integer float: decimal bool: boolean string: string
Data types can be changed by adding the corresponding conversion:
1 | var number = 42 |
But if you want static typing, you can define it like this:
1 | var names: int = 114 # explicitly specifying the data type |
Vector Data Types
Godot uses Vector2 and Vector3 to represent 2D and 3D coordinates, typically used for positions.
1 | var position = Vector3(1, 2, 3) # initialize coordinates |
Constants
The keyword is const:
1 | const constant = 10 |