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.

Open the main.tscn scene from the previous lesson. For now, the scene tree has only one node — Node2D.
The FileSystem panel shows main.tscn. This is our scene file inside the Godot project.
Select Node2D in the scene tree. The script will be attached to this node.
In the Inspector, the Script field is still empty (<empty>). This means Node2D does not have our code yet.
Click the attach script button. This is how we create the first GDScript for the selected node.
Godot suggests creating the script at res://main.gd. This works, but to keep the project organized, we will create a scripts folder.
In the FileSystem panel, open the context menu and create a new folder for scripts.
Change the path to res://scripts/main.gd. Now the code will be stored in the scripts folder.
When the path is correct, click Create. Godot will create main.gd and open it in the script editor.
Godot opened the new main.gd file. It already has template code: extends Node2D, _ready(), and _process().
Simplify the template and keep only what we need for this first script: _ready() and print().
Now the Inspector shows that main.gd is attached to Node2D.
Run the current scene. The game window is empty for now — that is normal, because our code prints to Output, not to the game screen.
The Output panel shows the message: “Привет, Godot! Сцена запустилась.” This means Godot called _ready(), and print() worked.

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

  1. We run the scene.
  2. Godot creates Node2D.
  3. Godot sees that main.gd is attached to Node2D.
  4. The node enters the scene tree.
  5. When the node is ready, Godot calls _ready().
  6. Inside _ready(), print() runs.
  7. 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.

← Back