Function Scripts
Overview
Function scripts are invoked via the 'Lua Script' option of Special Functions configuration page.
Typical uses
specialized handling in response to switch position changes
customized announcements
Limitations
should not exceed allowed run-time/ number of instructions.
all function scripts are stopped while one-time script is running (see Lua One-time scripts)
Function scripts DO NOT HAVE ACCESS TO LCD DISPLAY
Location
Place them on SD card in folder /SCRIPTS/FUNCTIONS/
Lifetime
script init function is called once when model is loaded
script run function is periodically called as long as switch condition is true
script is stopped and disabled if it misbehaves (too long runtime, error in code, low memory)
Script interface definition
Every script must include a return statement at the end, that defines its interface to the rest of OpenTX code. This statement defines:
script init function (optional, see Init Function Syntax)
script run function (see Run Function Syntax)
Example (interface only):
Notes:
local variables retain their values for as long as the model is loaded regardless of switch condition value
Advanced example (save as /SCRIPTS/FUNCTIONS/cntdwn.lua)
The script below is an example of customized countdown announcements. Note that the init function determines which version of OpenTX is running and sets the unit parameter for playNumber() accordingly.
Last updated