The smallest useful GDScript prints one line when its node starts:
Hello, World!
Three things happen here:
extends Nodesays the script controls aNode. Every script extends some class.func _ready():defines the function Godot calls once the node is in the scene.print()writes a line to the Output panel.
Running a Script in Godot
In the Godot editor, a script does nothing on its own. You attach it to a node:
- Create a scene with a root node (for example a
Node2D). - Select the node, then click the script icon to attach a new script.
- Write your code and press F6 to run the current scene.
The editor shows print() output in the Output panel at the bottom. On this page the Run button does the same thing: it puts the script on a node, runs one frame and shows what was printed.
Indentation Is the Syntax
GDScript has no braces. A block is the indented lines under a line that ends with ::
High score!
Saving...
Done
The two indented lines under if belong to it. print("Done") is back at the function's level, so it always runs.
Godot indents with tabs by default. Spaces are allowed, but a file must stick to one or the other. Mixing them stops the script before it runs:
Parse Error: Used tab character for indentation instead of space as used before in the file.
Comments
200.0
# starts a comment. ## starts a documentation comment: Godot shows it when you hover the variable or look it up in the built-in help. There is no block comment syntax; select lines and press Ctrl+K to comment them all.
print, prints and printt
print() joins its arguments with nothing between them. prints() puts a space between them, and printt() a tab:
HP: 7
HP: 7 of 10
The print and debugging page covers push_error(), print_rich() and the debugger.
Other Built-in Functions Godot Calls
_ready() is one of several virtual functions. Those that matter first:
extends Node2D
func _ready():
print("I am in the scene")
func _process(delta):
# every frame; delta is the time since the last frame in seconds
position.x += 100 * delta
func _input(event):
if event.is_action_pressed("ui_accept"):
print("Enter or Space pressed")
_process and _input need a running game loop and a window, so this block is shown and not run.
Frequently Asked Questions
How do I print Hello World in Godot?
Attach a script to any node and write func _ready(): with print("Hello, World!") indented under it. Run the scene and the text appears in the Output panel at the bottom of the editor.
Where does print output go in Godot?
To the Output panel at the bottom of the Godot editor, and to the terminal if you started Godot from one. print() never shows text inside the game window. For that, set the text of a Label node.
Should GDScript use tabs or spaces?
Godot's editor indents with tabs by default, and the official style guide uses tabs. Spaces work too, but one file must not mix them: Godot stops with "Used tab character for indentation instead of space as used before in the file."
How do I write a comment in GDScript?
Start it with #. Everything after # on that line is ignored. A line that starts with ## is a documentation comment, shown in the editor's built-in help for the variable or function below it.