GDScript Cheat Sheet
Quick Reference for Godot 4
Every GDScript pattern, syntax shortcut, and code snippet you'll actually use — organized in one place. Bookmark this page and stop Googling the same things over and over.
The first 4 sections are free to browse. Enter your email to unlock all 12 sections covering signals, exports, movement, tweens, state machines, and more.
Variables & Types
Variable declarations
Use var for mutable, const for compile-time constants, and static for shared state across instances.
var health: float = 100.0 # Typed mutable var name := "Hero" # Inferred type (String) const MAX_SPEED: float = 400.0 # Compile-time constant static var instance_count: int = 0 # Shared across instances
Core types
GDScript's built-in types cover everything from math to collections.
var hp: int = 10
var speed: float = 3.14
var label: String = "Player"
var alive: bool = true
var pos: Vector2 = Vector2(100, 200)
var color: Color = Color.CORAL
var items: Array[String] = ["sword", "shield"]
var stats: Dictionary = {"atk": 5, "def": 3}Enums
Define named constants for state machines, directions, and more.
enum State { IDLE, RUN, JUMP, FALL }
enum Element { FIRE = 10, ICE = 20, LIGHTNING = 30 }
var current_state: State = State.IDLE
var weakness: Element = Element.FIREFunctions
Function syntax
Type-annotate parameters and return values to catch bugs early and get autocomplete.
func heal(amount: float) -> void:
health = min(health + amount, max_health)
func get_damage_multiplier(element: Element) -> float:
if weakness == element:
return 2.0
return 1.0
# Lambda / callable
var double := func(x: int) -> int: return x * 2Built-in virtual methods
Override these to hook into Godot's lifecycle. They're called automatically by the engine.
func _ready() -> void: # Node entered tree
pass
func _process(delta: float) -> void: # Every frame
pass
func _physics_process(delta: float) -> void: # Fixed timestep
pass
func _input(event: InputEvent) -> void: # Raw input
pass
func _unhandled_input(event: InputEvent) -> void:
passControl Flow
Conditionals & matching
match is GDScript's pattern-matching — like switch but more powerful.
# If / elif / else
if health <= 0:
die()
elif health < 30:
play_low_hp_warning()
else:
regenerate()
# Match (pattern matching)
match state:
State.IDLE:
play_idle_anim()
State.RUN:
velocity.x = direction * speed
State.JUMP, State.FALL:
apply_gravity(delta)
_:
push_warning("Unknown state")Loops
for-in works on ranges, arrays, dictionaries, strings, and nodes.
# Range loop
for i in range(5): # 0,1,2,3,4
print(i)
# Array loop
for item in inventory:
item.use()
# Dictionary loop
for key in stats:
print("%s: %d" % [key, stats[key]])
# While loop
while not is_on_floor():
velocity.y += gravity * delta
move_and_slide()Signals
Signal basics
Signals are Godot's observer pattern. Declare, connect, emit — zero coupling.
# Declare
signal health_changed(new_hp: float)
signal died
# Emit
func take_damage(amount: float) -> void:
health -= amount
health_changed.emit(health)
if health <= 0:
died.emit()
# Connect (from another node)
func _ready() -> void:
player.health_changed.connect(_on_hp_changed)
player.died.connect(_on_player_died)Signal bus pattern
A global autoload that acts as a central event dispatcher. No more get_node spaghetti.
# Autoload as "Events" extends Node signal player_damaged(amount: float) signal coin_collected(value: int) signal level_completed signal game_paused(is_paused: bool) # Any node can emit: # Events.player_damaged.emit(25.0) # Any node can listen: # Events.coin_collected.connect(_on_coin)
Unlock the Full Cheat Sheet
Get instant access to all 12 sections covering 18+ patterns, plus weekly GDScript tips delivered to your inbox. Free forever.
No spam. Unsubscribe anytime.
Keep learning
Want to Go Deeper?
This cheat sheet gives you the syntax. Our micro-courses teach you the why and when — with hands-on video walkthroughs you can follow in your own Godot editor.
Browse CoursesMore free resources
We publish free GDScript tutorials every week covering signals, shaders, state machines, multiplayer, and more. Read our latest tutorial →