On a phone, reading vertically is fine. Code and interactive tasks are more comfortable in landscape mode.
Lesson 002
002. First Script
Attach GDScript to Node2D, create scripts/main.gd, write _ready(), print a message with print(), and check the result in Output.
What we study
In this lesson, we attach GDScript to a node for the first time. The code is small: it prints a message to Output.
This is still an important moment. Game behavior starts here: the scene stops being only a set of objects and receives its first command.
Why a script is needed
Without scripts, a scene only stores objects. It knows which nodes are inside, what they are called, and where they are placed.
A script makes an object alive: a button reacts, a character moves, a coin disappears, and a timer counts time. Today we start with the smallest reaction: printing text to Output.
What we will get
After running the scene, the lower Output panel will show this message:
Привет, Godot! Сцена запустилась.This means the scene ran, Node2D was created, Godot called _ready(), and print() worked.
Step by step in Godot
Move in short steps: click, look, understand, check. Before rewriting code, make sure Node2D is selected and the script path is correct.
Lesson code
Keep this code in scripts/main.gd:
extends Node2D
func _ready() -> void:
print("Привет, Godot! Сцена запустилась.")Code breakdown
extends Node2D
The script is attached to Node2D and extends its behavior.
func _ready() -> void:
This is a special Godot function. It is called when the node is ready.
print(...)
Prints a message to the Output panel. This is not text on the game screen; it is debug output for the developer.
Important step: Ctrl + S
After changing the script, press Ctrl + S. This saves the script file. If you forget to save it, you may run an old version of the code or get confused.
What happens when we run it
- We run the scene.
- Godot creates Node2D.
- Godot sees that main.gd is attached to Node2D.
- The node enters the scene tree.
- When the node is ready, Godot calls _ready().
- Inside _ready(), print() runs.
- The text appears in Output.
Common mistakes
- forgot to select Node2D before Attach Script;
- saved the script somewhere other than scripts/main.gd;
- forgot to press Ctrl + S after changing the code;
- wrote ready() instead of _ready();
- expected the text in the game window, but print() writes to Output;
- broke the indentation inside the function.
Bad:
func _ready() -> void:
print("Привет")Good:
func _ready() -> void:
print("Привет")Small task
Change the text inside print(), save the file with Ctrl + S, and run the scene again.
extends Node2D
func _ready() -> void:
print("Мой первый скрипт работает!")Next step
In the next lesson, we will add the first visible object — Sprite2D. For now, the script only prints a message to Output. Next, we will see an object on the screen and start changing its properties through the Inspector and code.