Lesson 02

Your first node, script, and the game loop

We'll make a node print to the screen, react to time, and respond to a key. These three things — ready, process, and input — are the heartbeat of every Godot game.

▸ By the end of this lesson: A script that greets on start, counts every frame, and reacts to a key press

2.1Make a scene with a root node

  1. In the Scene dock, click + Other Node (or the big "Other Node" button on an empty scene).
  2. Search Node, pick plain Node, and click Create. It appears as the root.
  3. Double-click its name and rename it Playground.
  4. Save with Ctrl/Cmd+S as playground.tscn.

2.2Attach a script

  1. Right-click PlaygroundAttach Script.
  2. Leave language as GDScript and path as playground.gd. Click Create.
  3. The Script editor opens with a near-empty file.

Replace everything in it with this:

playground.gdgdscript
extends Node

# _ready() runs once, the moment this node enters the scene tree.
func _ready() -> void:
	print("GridFall playground is alive.")

# _process(delta) runs every rendered frame.
# delta = seconds since the last frame (a small float like 0.016).
func _process(delta: float) -> void:
	# Uncomment to see it fire constantly:
	# print(delta)
	pass

# _input(event) runs whenever an input event happens.
func _input(event: InputEvent) -> void:
	if event is InputEventKey and event.pressed:
		print("You pressed a key: ", event.as_text())

Indentation is tabs

GDScript uses indentation for blocks like Python. Godot's editor inserts a real Tab by default — don't mix tabs and spaces or you'll get a parse error. If you paste code, the editor usually fixes it; if not, select all and press the auto-indent shortcut.

2.3Run this scene

  1. Press F6 (Run Current Scene), or the clapperboard icon top-right.
  2. A blank game window opens. Look at the Output panel at the bottom of the editor.
  3. You should see GridFall playground is alive.
  4. Click the game window and press some keys — each press prints a line.

The three lifecycle methods

_ready() = setup, once. _process(delta) = per-frame logic, uses delta so movement is framerate-independent. _input(event) = respond to raw input. You will use all three constantly.

2.4Typed vs untyped — and why we type

Notice -> void and delta: float. Those are optional type hints. GridFall uses them everywhere because they let Godot catch mistakes before you run, and they make autocomplete far better. Untyped GDScript works too, but typed code is how you avoid the silent bugs that plague bigger projects.

Checkpoint — expected state