Skip to contentSkip to Content

Functions

FUNCTION defines a named, reusable block; call it later with name():

functions.hdc
FUNCTION open_run() GUI r DELAY 500 END_FUNCTION open_run() STRING notepad ENTER open_run()

Rules the compiler enforces

  • Names are case-sensitive identifiers (letters, digits, underscores) and can’t reuse a reserved command or key name.
  • Every FUNCTION needs a matching END_FUNCTION. A stray END_FUNCTION, a duplicate name, or a definition nested inside another function is a compile error.
  • A function may call other functions, including ones defined later in the file or each other (mutual recursion). Call depth is bounded on the device — 8 levels deep — so a runaway recursive script is skipped safely rather than crashing the device.

Functions are also a flash-efficiency tool: a function’s body is stored once no matter how many times it’s called. See Best practices and the flash variants table for how script size maps to storage.

Last updated on