Translate one C# script habit at a time instead of rewriting a full controller.
Code Sandbox. Practice GDScript structure, typing, exports, and static checks in the browser.
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.
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 controlmove_and_slide()- Built-in movement functionis_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 aforeach 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.0is a float from then on.var speed = 300.0is 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. $Pathreplaces GetComponent.$Sprite2Dis shorthand forget_node("Sprite2D")and resolves against the scene tree by name, not against a type. Cache it once with@onready var sprite := $Sprite2Drather than looking it up every frame.- Signals are declared, emitted, and connected. Write
signal died, fire it withdied.emit(), and listen withenemy.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. Useis_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 setvelocityand callmove_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.
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.
Convert one Blueprint event chain into a small function.
Prefer short functions, typed variables, and exported tuning fields.
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.