Interactive Lab quest

Code Sandbox. Practice GDScript structure, typing, exports, and static checks in the browser.

10-20 min · Godot 4.7

GDScript Code Sandbox

Practice GDScript snippets in a browser editor with syntax highlighting and saved snippets. Real GDScript execution requires the Godot editor — this sandbox is for reading, editing, and copying patterns. Pair it with the GDScript cheat sheet and our typed recipe library.

Examples 12
player_movement.gd GDScript
extends CharacterBody2D

@export var speed := 300.0
@export var jump_force := -400.0

var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")

func _physics_process(delta: float) -> void:
# Apply gravity
velocity.y += gravity * delta
# Jump when on floor
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = jump_force
# Horizontal movement
var direction := Input.get_axis("move_left", "move_right")
velocity.x = direction * speed
move_and_slide()

Player Movement

Basic platformer movement with jump

Static checks

  • Declares a Godot base node
  • Uses typed GDScript or inferred typed values
  • Includes a Godot lifecycle, signal, or scene API

Key concepts

  • CharacterBody2D - Physics body for player control
  • move_and_slide() - Built-in movement function
  • is_on_floor() - Ground detection
  • @export - Expose to Inspector

How to use these snippets in a real project

Every snippet on this page is a complete script for one node. To use one, create the node type named in its extends line, select that node in the Scene dock, click Attach Script in the Inspector, and paste the snippet over the template Godot generates. The script becomes that node's behaviour. There is no component to add afterwards and nothing to register anywhere, because in Godot the script belongs to the node it sits on.

If a snippet declares @export variables they appear in the Inspector the moment the file saves, which is where a designer tunes them without opening the script. That is the practical reason to mark a value as exported rather than leaving it a plain var: exported data is part of the scene, so two instances of the same script can carry different numbers.

The editor above gives you syntax highlighting, drafts saved in your own browser, and the structural checks in the panel beside it. It does not execute GDScript. The language is run by the Godot engine, and almost everything a script does depends on the scene tree around it, which only the real editor has. Draft here, then paste into a scene to watch it behave.

GDScript rules that catch C# developers out

  • Indentation is the block. There are no braces and no semicolons. A function body, an if, and a for each open with a colon and are delimited by indentation. Mixing tabs and spaces inside one file is a parse error, not a style warning.
  • := infers a type, = does not. var speed := 300.0 is a float from then on. var speed = 300.0 is a Variant that will happily accept a string later and fail somewhere else. Prefer the inferred form.
  • Return types use an arrow. func take_damage(amount: int) -> void: gives you autocompletion and catches the same class of mistake the C# compiler would catch for free.
  • $Path replaces GetComponent. $Sprite2D is shorthand for get_node("Sprite2D") and resolves against the scene tree by name, not against a type. Cache it once with @onready var sprite := $Sprite2D rather than looking it up every frame.
  • Signals are declared, emitted, and connected. Write signal died, fire it with died.emit(), and listen with enemy.died.connect(_on_enemy_died). There is no delegate type to define and no event keyword.
  • queue_free() is not Destroy. It frees the node at the end of the current frame, which is why a freed node still answers this frame and is gone the next. Use is_instance_valid() before touching a reference you may have freed.
  • Frame callbacks are split. _process(delta) runs every rendered frame; _physics_process(delta) runs on the fixed physics tick and is the only correct place to set velocity and call move_and_slide().
  • Arrays and dictionaries are built in. Array[int] gives a typed array, and dictionaries use {"key": value} literals. There is no using directive to add first.
Tutor Checkpoint

Lock the pattern in

Before jumping to the next page, turn the idea into one tiny scene or script. That is where the Godot habit sticks.

Unity habit

Translate one C# script habit at a time instead of rewriting a full controller.

Unreal habit

Convert one Blueprint event chain into a small function.

Godot habit

Prefer short functions, typed variables, and exported tuning fields.

Try this

Write a HealthComponent with one signal and two exported values.

Frequently asked questions

Can I run real GDScript in the Code Sandbox?
No. The sandbox is a GDScript practice editor with syntax highlighting, saved snippets, and lightweight static checks. Full execution requires the Godot editor.
Is my code saved between sessions?
Yes, edited code is saved to your browser's localStorage automatically. It persists until you clear your browser data.