GD Collection

Functions:

Functions in programming are modular units of code designed to perform specific tasks.
They encapsulate a set of instructions, allowing for code reuse and organization.
table by: https://generalistprogrammer.com/cheatsheets/godot-gdscript

Code Description Example
func function_name(params): Define function func take_damage(amount: int): health -= amount
func name() -> Type: Function with return type
func get_health() -> int: return health
func name(param = default): Function with default parameters func heal(amount = 10): health += amount
return value Return value from function func is_alive() -> bool: return health > 0
pass Empty function body placeholder func _ready(): pass
static func name(): Static function (callable without instance) static func calculate_damage(base, multiplier): return base * multiplier
func _ready(): Called when node enters scene tree func _ready(): print("Node is ready") setup_game()
func _process(delta): Called every frame func _process(delta): position.x += speed * delta
func _physics_process(delta): Called every physics frame (fixed timestep) func _physics_process(delta): velocity.y += gravity * delta move_and_slide()
func _input(event): handles input events func _input(event): if event is InputEventKey: if event.pressed and event.keycode == KEY_SPACE: jump()
func _unhandled_input(event): Handle input not consumed by UI func _unhandled_input(event): if event.is_action_pressed("shoot"): fire_weapon()
func _enter_tree(): Called when node enters tree (before _ready) func _enter_tree(): print("Entering scene tree")
func _exit_tree(): Called when node exits tree func _exit_tree(): cleanup_resources()