Skip to main content
Coding Quests
The Scroll Library
Tutorials

GDScript Tutorial for Beginners: Your First Godot 4 Script

June 16, 2026Updated July 19, 20269 min read

If you've never written code before, GDScript is a kind first language. It looks a lot like Python, it's built into Godot, and you can see your changes run a few seconds after you type them. That fast loop is the whole reason it sticks.

This is the part most "learn Godot" videos rush past. Let's slow down and actually understand what you're typing.

The short version: GDScript is Godot's built-in scripting language. You attach a script to a node, and the script tells that node what to do. It reads like Python: var makes a variable, func makes a function, indentation groups code, and Godot calls _ready() once when the node loads and _process(delta) every frame. Learn that handful of pieces, plus arrays, signals, and Resources near the end, and you can write real game logic.

Before you start: you need Godot 4 installed and a scene with a node to attach a script to. No prior programming required, GDScript can genuinely be your first language. Written for Godot 4.x; the syntax below is stable across the 4.x line. Keep the GDScript cheat sheet open in another tab for the exact forms once concepts click, see how to learn Godot for where this fits in the bigger roadmap, and browse more resources by topic in the Godot tutorials library.

What GDScript is

GDScript is Godot's own scripting language. Every script you write attaches to a node, and that script controls what the node does: how it moves, when it takes damage, what happens when it's clicked. You're not writing a whole program from scratch. You're handing one node a set of instructions.

If you know Python, you'll feel at home in about ten minutes. If you don't, that's fine, because the basics are small.

Variables

A variable is a labeled box that holds a value. You make one with var:

GDScript
var player_name = "Knight"
var health = 100
var speed = 250.0
var is_alive = true

Godot can guess the type from the value, but you can also say it outright. Typed variables catch mistakes early and give you better autocomplete, so get in the habit:

GDScript
var health: int = 100
var speed: float = 250.0
var player_name: String = "Knight"

Functions

A function is a named block of steps you can run on demand:

GDScript
func take_damage(amount: int) -> void:
health -= amount
print("Took ", amount, " damage. Health is now ", health)

func starts it, take_damage is the name, amount: int is the value you pass in, and -> void means it doesn't hand anything back. Indentation matters in GDScript, same as Python. The indented lines are what's inside the function.

The two functions you'll use constantly

Godot calls some functions for you automatically. Two of them you'll use in nearly every script:

GDScript
func _ready() -> void:
# Runs once, when the node enters the scene
print("I'm alive!")
func _process(delta: float) -> void:
# Runs every single frame
position.x += 100 * delta

_ready() is your setup. _process(delta) runs every frame, which is how you do anything continuous, like movement. That delta is the time since the last frame, and multiplying by it keeps your game running at the same speed on a fast or slow machine. Forgetting delta is the number one beginner mistake, so notice it now.

Talking to nodes

Your script can reach other nodes in the scene. The $ shortcut grabs a child node by name:

GDScript
func _ready() -> void:
$Sprite2D.modulate = Color.RED # tint the sprite red
$Label.text = "Game Start"

For nodes you use a lot, cache a reference once with @onready so you're not looking it up every time:

GDScript
@onready var sprite: Sprite2D = $Sprite2D

Tweak values from the editor

Slap @export in front of a variable and it shows up in the Inspector. Now you can change speed or health without opening the script, which is huge once you start tuning your game:

GDScript
@export var speed: float = 250.0
@export var max_health: int = 100

Decisions and loops

if runs code when something is true. for repeats code:

GDScript
if health <= 0:
print("Game over")
elif health < 30:
print("Careful, low health")
else:
print("Doing fine")
for i in 3:
print("Spawning enemy ", i)

That's the core of the language. Variables, functions, the two lifecycle calls, node access, and a couple of control structures. A few more pieces show up in almost every real script, though, so let's meet them.

Arrays and dictionaries

An array is an ordered list. A dictionary is a set of labeled values. You will use both constantly: an array for an inventory or a wave of enemies, a dictionary for one thing's stats.

GDScript
var inventory = ["sword", "potion", "key"]
inventory.append("shield") # add to the end
print(inventory[0]) # "sword" (counting starts at 0)
print(inventory.size()) # 4
var stats = {"health": 100, "speed": 250, "name": "Knight"}
print(stats["health"]) # 100
stats["health"] -= 10 # take 10 damage

Loop over either one:

GDScript
for item in inventory:
print("Carrying ", item)
for key in stats:
print(key, " = ", stats[key])

Arrays and dictionaries are how one script holds many things at once. An inventory is an array of items; a save file is usually a dictionary.

Signals: how nodes talk

A signal is a message a node sends out when something happens, without knowing who is listening. A button emits pressed, and you connect a function to react to it.

GDScript
func _ready() -> void:
$Button.pressed.connect(_on_button_pressed)
func _on_button_pressed() -> void:
print("Clicked!")

This is the single most important pattern in Godot, because it keeps your systems from depending on each other. It gets its own guide: the Godot 4 signals tutorial.

Resources: data you can save and reuse

A Resource is a lightweight data container that lives in a .tres file instead of the scene tree. Item definitions, character stats, and settings are usually Resources, because you can create them in the editor and load them anywhere.

GDScript
# item.gd
class_name Item
extends Resource
@export var name: String
@export var damage: int

Right-click in the FileSystem, make a new Item resource, fill in the fields, and you have a reusable sword.tres with no extra code. Resources are how you separate a game's data from its behavior.

Your first real script

Here's a complete script that moves a sprite and prints when it's set up. Attach it to a Node2D and press play:

GDScript
extends Node2D
@export var speed: float = 200.0
func _ready() -> void:
print("Moving right at ", speed, " pixels per second")
func _process(delta: float) -> void:
position.x += speed * delta

That's a working program. It runs, it moves, and you wrote it.

Build It Yourself

You have the pieces now. Don't copy the script above, build a different one from scratch:

  1. Attach a script to a Node2D and give it an @export var speed: float.
  2. In _process(delta), move it right, but make it reverse direction when its position.x passes 400 and again when it drops below 0. (Hint: store a direction variable that is 1 or -1 and flip it.)
  3. Add var bounces := 0 that counts each time it turns around, and print the count.
  4. Give it an array of three colors and, every time it bounces, set modulate to the next color in the array.

If you can do that without looking back at this page, you understand variables, _process, arrays, and conditions well enough to start building real mechanics. If you get stuck, that is the useful part: it shows you exactly which piece to reread.

Where to go next

Reading about a language and using it are different skills, and only one of them makes you a developer. Our Code From Zero quest walks you from your literal first line to attaching real scripts to nodes, and it's completely free. The first eight lessons run right in your browser, so you can start before you've even installed anything.

Keep the GDScript cheat sheet open in another tab while you build; it's the reference you'll come back to for months. When events and decoupling come up, the signals tutorial is the next concept to learn. And for the full picture of what to learn and build in what order, follow the project-based Godot roadmap.

FAQ

Is GDScript hard to learn?

Not for a first language. The syntax is small and readable, close to Python, and Godot's fast edit-run loop means you see results in seconds. The hard part of game dev isn't the language, it's learning to wire systems together, which comes with practice.

Do I need to know Python before GDScript?

No. GDScript looks like Python, so Python knowledge transfers, but plenty of people learn GDScript as their very first language. The indentation rules and clean syntax are beginner-friendly on their own.

Should I learn GDScript or C# in Godot?

Start with GDScript. It's built in, it has the best editor integration, and almost every Godot tutorial uses it. C# is worth it later if you need raw performance or already know it well. We compared them in detail in GDScript vs C#.

gdscriptbeginnertutorial

Stop reading. Start building.

Beat the demo boss by writing real Godot code, then build this for real in the Code From Zero quest.

Free, and no card needed. Built by a real person, with new quests every month.

Get the next Godot build in your inbox

New quests, project breakdowns, and game-dev tips. Free, no spam, unsubscribe anytime.

Written by Omar

We teach Godot 4 by making you build complete systems: inventories, save systems, action roguelike controllers, enemy AI. The scrolls are free. The quests are where it sticks.