Lessons

lesson 11 / 15

Local and global variables

A function can create a local variable with local. Local variables belong to that function call and do not become global configuration.

kongue
prefix: "Kongue"

func greet {
    local message = "$prefix says hello to $1"
    print $message
}

main {
    greet "the builder"
}

The global command is available to embedding projects that need a function to update a top-level variable. Prefer local variables when a value only exists to support one function; this keeps functions easier to understand and reuse.