Skip to content

Code Standards

AM-Mikey edited this page Mar 6, 2026 · 8 revisions

Here's an example of how a script should be structured.

Script Standards

extends Node

const CONSTANT_ONE: String = "Number 1"
const CONSTANT_TWO := "Number 2"

signal signal_one()
signal signal_two()

@export var var_one
@export var var_two

var var_three
var var_four

@onready var var_five
@onready var var_six

func _ready():
 if var_one == null:
  printerr("ERROR: THIS IS AN ERROR")
 elif var_one == -1:
  print("WARNING: This is a warning")

func _physics_process(_delta):
 pass



### SECTION HEADER ###

func function_one():
 await get_tree().create_timer(1.0, false, true).timeout #for 2d nodes, so they pause and use physics process time

func function_two():
 await get_tree().create_timer(1.0, true, false).timeout #for ui nodes and others, so they don't pause and use process time



### STATE MACHINE ###

func enter_statename():
 pass

func do_statename(): #called on physics_process
 pass

func exit_statename():



### GETTERS ###

func getter_one() -> Array:
 var out = []
 return out

### HELPERS ###

func helper_function_one():
 pass

func helper_function_two():
 pass



### SIGNALS ###

func _local_signal():
 pass

func global_signal():
 pass

Avoiding shadowing in class scripts

extends Node
class_name ExampleClass

func _ready(): #for parent class
 setup()

func setup(): #for children. Since this will be shadowed, leave it blank
 pass

func _physics_process(delta): #for parent
 _on_physics_process(delta)

func _on_physics_process(delta): #for child
 pass

func _process(delta): #for parent
 _on_process(delta)

func _on_process(delta): #for child
 pass

Clone this wiki locally