Skip to reading
GDScript Programming & Godot

3. Indentation, lines and comments

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page
Code example
# A whole-line comment.
func run() -> int:
    var points: int = 5  # A comment after an instruction.
    if points > 0:
        print("There are points to award.")
    return points

A colon opens a function, branch, loop or class block. Indentation tells Godot which lines belong to that block. There is no end keyword. Use one consistent indentation style; the editor’s Tab key is a sensible default.

# begins a comment. ## is used for documentation comments in Godot’s documentation workflow. // is not a GDScript comment marker. Triple-quoted text is a string, not a separate block-comment system.

Code example
func run() -> void:
    await ShowMessage({
        "text": "The workshop is quiet.",
        "duration": 2,
        "blockInput": false
    })

Unlike PCA Script, GDScript allows a call, array or dictionary to continue across lines inside brackets. Use this to keep options readable. A line with only pass is a valid empty function body while you are building the rest.

Page 11 of 378Permalink
Go to page