Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save TheDuriel/e34278a84ea163858d2d5e578b666dbc to your computer and use it in GitHub Desktop.
Save TheDuriel/e34278a84ea163858d2d5e578b666dbc to your computer and use it in GitHub Desktop.
theDuriels Standard Godot scripting Language Conventions Version 1.0
Aka.: DSGLC v1.0
The following document outlines, in rough terms, the standard language conventions used by TheDuriel in all his projects.
Annotations are marked with ->
Unless otherwise noted there are no empty lines between blocks.
# -> Start the file with a Copyrigth disclaimer. If any.
# -> This should done by commenting out each line using a hashtag symbol.
# Copyright Manuel 'TheDuriel' Fischer 2019 All Rights Reserved
# -> Add the tool keyword if this is a tool script.
tool
# -> Extend the base class you wish to build upon
extends CamelCaseObjectName
# -> Give the class a CamelCase name.
# -> Do not give it a name if: it is the root node of a Scene file unique to that scene.
# -> Or if it is a one off that is only used in a single place.
# -> Or it is an Autoload Singleton.
classname CamelCaseClassName
# -> Add a docs string describing the kind, and purpose, of the script.
# -> Line One should state the name of the class, and its instanced used case.
# -> Standalone classes use this format.
# -> Add "singleton" if the class is meant to be used as a singleton.
# -> Add "base" if the class is meant to be extended, instead of being used directly.
# <ClassName> (Singleton) (Base) Class Script
# -> Dedicated Scene Classes us this format.
# <SceneName> Scene Script
# -> Resources use this format.
# <ClassName> Resource Script
# -> Line Two should be a one sentence description of what the class does.
# Provides functionality for doing things.
# -> Add an Empty Line. This indicates the start of the Variable declaration Block.
# -> List exported variables.
# -> Names should be CAPSCASE for sudo constants.
# -> And snake_case for public variables.
# -> Providing a default value prevents unexpected behavior and nulled properties.
# -> You can use setget functions with tool scripts to validate values beyond what export hints allow.
# -> When exporting a NodePath, you should append _path to the variable name.
export(<type>, optional hints) var EDITOR_ONLY: <type> = <default_value>
export(<type>, optional hints) var public_variable: <type> = <default_value>
# -> Add an Empty Line. This indicates the start of the Constants variable Block.
# -> List constants. Names should be CAPSCASE.
const A_CONSTANT: <type> = <value>
# -> List Enums. Do not use multiple lines unless you break the line limit.
# -> If you do, indent the continuing line with two tabs.
enum STATE {
STANDING,
WALKING,
RUNNING}
# -> In the example of a STATE constant, it is often desired to track the current state.
# -> Do this with a private variable right after the associated Enum. See private variables further below.
var _state: int = STATE.STANDING
# -> Add an Empty Line. This indicates the start of the public variable Block.
# -> Public variables are meant to be editable by other objects.
# -> You can use setget functions to extend their behavior, and validate opterations made to them.
var a_public_var: <type> = <default_value> setget set_a_public_var, get_a_public_var
# -> Add and Empty Line. This indicates the start of the Node reference variable Block.
# -> These are private variables, not meant to be set by another object.
# -> This is indicated through a leading underscore _.
# -> Node references also have the _node suffix.
# -> Always use $ in conjunction with strings "".
# -> This caches the path at compile time, and makes the lookup marginally faster.
# -> Never use "../" or get_parent() it will cause errors.
onready var _childnodename_node: <nodetype> = $"path/to/node"
# -> Sometimes you might export a NodePath. In that case you must resolve the path on ready.
onready var _childnodename_node: <nodetye> = get_node(exported_node_path)
# -> Add an Empty Line. This indicates the start of the private variable Block.
# -> Private variables are distinguished from public variables using a leading underscore.
# -> You can provide setget functions for save editing by other objects, but this should be avoided.
var _a_private_var: <type> = <default_value>
# -> Add Two Empty Lines. This indicates the start of the Functions Block.
# -> All functions are to be seperated by two empty lines from here on out.
# -> Start with Setter and Getter functions in pairs.
func set_a_public_var(new_value: <type>) # -> void:
a_public_var = new_value
func get_a_public_var() # -> <type>:
return a_public_var
# -> Start with virtual functions provided by the engine.
# -> Only define a virtual function if you actually use it.
# -> _notification
func _notification(what: int) # -> void:
if what == Object.NOTIFICATIONCONSTANT:
pass
# -> _init
func _init(varargs) # -> void:
pass
# -> When extending a class which already defines init.
# -> The declaration must look like this:
func _init(varargs).(varargs) # -> void:
pass
# -> _ready
func _ready() # -> void:
pass
# -> _input, _unhandled_input, _input_event, _gui_input
# -> You can prevent events from cascading to other nodes by using:
# -> get_tree().set_input_as_handled() for non Control nodes.
# -> Control.accept_event() for Control nodes.
func _input(event: InputEvent) # -> void:
if event is InputEvent<type>:
pass
func _unhandled_input(event: InputEvent) # -> void:
if event is InputEvent<type>:
pass
# -> Only available for CollisionObject Nodes
func _input_event(event: InputEvent) # -> void:
if event is InputEvent<type>:
pass
# -> Only avaialble for Control Nodes
func _gui_input(event: InputEvent) # -> void:
if event is InputEvent<type>:
pass
# -> _process, _physics_process, _integrate_forces, other node specific virtuals.
func _process(delta: float) # -> void:
pass
func _physics_process(delta: float) # -> void:
pass
# -> Only available for RigidBody Nodes
func _integrate_forces(state: PhysicsDirectBodyState) # -> void:
pass
# -> Public functions. using snake_case
func a_public_func(mandatory_arg: <type>, optional_arg: <type> = <default_value>) # -> return_type:
pass
# -> Private functions, with a leading underscore _.
func _a_private_func(mandatory_arg: <type>, optional_arg: <type> = <default_value>) # -> return_type:
pass
# -> Signal Callback Functions. With a leading _on_
# -> Callback functions must have a matching number of arguments, to what the signal emitts.
# -> You can connect varying argument count signals to a single function, by adding additional optional arguments.
func _on_somesignal(signal_arg: <type>) # -> void:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment