⌘K

Functions

Updated 16 Mar 2026

Defining a function

define heal($amount):
    set $hp = player.health + $amount
    if $hp > 20:
        set $hp = 20
    console health player.name $hp
    send "&aHealed for $amount HP!" to player

Calling a function

call heal(5)
call heal($bonus)

Functions with return values

define clamp($value, $min, $max):
    if $value < $min:
        return $min
    if $value > $max:
        return $max
    return $value

set $safe = clamp($damage, 0, 20)

Return values can also be used inline as expressions.

Namespaced functions

Use a colon to namespace functions and avoid name collisions across scripts:

define math:square($x):
    return $x * $x

set $area = math:square(5)   # 25

Recursion limit

Kode prevents infinite recursion by stopping at 32 nested function calls.