When writing or reviewing GDScript code, strictly follow the official Godot Engine GDScript style guide and file naming conventions: --- ### **Code Formatting** 1. **Indentation**: Use **4 spaces** (no tabs). 2. **Line Length**: Keep lines under **100 characters** where possible. 3. **Naming Conventions**: - **Variables/functions**: `snake_case` (e.g., `player_health`, `calculate_damage()`). - **Constants**: `UPPER_SNAKE_CASE` (e.g., `MAX_SPEED = 100`). - **Class Names**: `PascalCase` (e.g., `class_name Player.gd`). - **Signals**: `snake_case` (e.g., `signal player_died`). 4. **Spacing**: - Add spaces around operators (`x = y + z`, not `x=y+z`). - No space after `(` or before `)` in function calls (e.g., `func(a, b)`). 5. **Braces**: Open braces on the same line for `if`, `for`, `func`, etc.: ```gdscript if x > 0: print("Positive") ``` 6. **Docstrings**: Use **Godot’s built-in docstring format** for functions: ```gdscript ## Calculates the player's speed based on input. ## @param delta: Time since last frame (float). ## @return: The adjusted speed (float). func calculate_speed(delta: float) -> float: return base_speed * delta ``` 7. **Type Hints**: Always include type hints for parameters and return values (Godot 4+). 8. **Avoid Redundancy**: Omit redundant `self.` unless required for clarity. --- ### **File Naming Conventions** 1. **Script Files**: - Use **`snake_case`** for `.gd` files (e.g., `player.gd`, `enemy_ai.gd`). - Match the filename to the **class name** (if the script defines a class). Example: If the class is `Player`, the file should be `player.gd`. 2. **Scene Files**: - Use **`PascalCase`** for `.tscn` files (e.g., `Player.tscn`, `MainMenu.tscn`). - Match the filename to the **root node** of the scene. 3. **Resource Files**: - Use **`snake_case`** for `.tres` or `.res` files (e.g., `player_stats.tres`). 4. **Folders**: - Use **`snake_case`** for directories (e.g., `scripts/`, `assets/sprites/`). - Group related files logically (e.g., `player/` for `player.gd`, `player.tscn`). --- **Reference**: [Godot GDScript Style Guide](https://docs.godotengine.org/en/stable/getting_started/scripting/gdscript/gdscript_styleguide.html).