Skip to content

Instantly share code, notes, and snippets.

@fguillen
Last active June 6, 2023 10:30
Show Gist options
  • Save fguillen/189c39adb32d7e17b0c1b5cb4c6f87d9 to your computer and use it in GitHub Desktop.
Save fguillen/189c39adb32d7e17b0c1b5cb4c6f87d9 to your computer and use it in GitHub Desktop.
Godot GD script template with the order of the code sections
# meta-name: Code style template
# meta-description: Empty script with the order of the code sections
# -- 01 @tool
# -- 02 class_name
# -- 03 extends
extends _BASE_
# -- 04 # docstring
#
# -- 05 signals
# -- 06 enums
# -- 07 constants
# -- 08 exported variables
# -- 09 public variables
# -- 10 private variables
# -- 11 onready variables
#
# -- 12 optional built-in virtual _init method
# -- 13 optional built-in virtual _enter_tree() method
# -- 14 built-in virtual _ready method
# -- 15 remaining built-in virtual methods
# -- 16 public methods
# -- 17 private methods
# -- 18 signal listeners
# -- 19 innerclasses
@fguillen
Copy link
Author

fguillen commented Apr 7, 2023

I find myself wasting valuable mental brain cycles each time I want to add a new section to my GD script. A new public variable, a new signal, a new private method...

I ask myself: "Where is the best place to put this code so it is coherent with the rest and I can find it easily in the future?"

Luckily the people from Godot have a suggestion for how to organize our GD script files:

But having to look at this page each time I want to find the proper location of a new piece of code was also annoying.

I created this simple script template.

Add this script template to your Godot project on this path:

./script_templates/node/code_style.gd

And you will have all your new GD scripts already with all the sections marked.

I'm adding the prefix

# -- 

to all comments so they are easy to scan and delete when you are ready to clean up.

This may be not for you, but for me, it is a game changer :). Life is full of small hacks like this. Hope it is useful for you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment