Coding Quests
The Scroll Library
Tutorials

GDScript Tutorial for Beginners: Your First Godot 4 Script

June 16, 20266 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.

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 most of the language. Variables, functions, the two lifecycle calls, node access, and a couple of control structures. Everything else is built on top of these.

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.

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.

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

Reading is the map. The quest is the territory.

Build this for real in the Code From Zero quest. It's free, no card needed.

Start the Quest
Written by Coding Quests

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