One-Time Scripts
Purpose
One-time scripts are used mainly to perform tasks that are not connected with flying. In example ELRS configuration LUA script. They do their task and are then terminated (by user or function) and unloaded.
Execution & Lifetime
Script is executed when user selects "Execute" on a script file from SD card browser screen, or opens a Lua Tool, or creates a new model with a Wizard script.
The script executes until:
it returns value different from 0 (except returning string that contains new script name to be executed)
is forcefully closed by user by long press of EXIT key
is forcefully closed by system if it misbehaves (e.g. run-time error or low
memory)
Running a One-Time script will suspend execution of all other currently loaded Lua scripts (Custom, Telemetry, and Functions). They are automatically restarted once the One-Time script is finished. This is done to provide enough system resources to execute the One-Time script.
File Location
One-Time Scripts can be placed anywhere on SD card, however, the folder /SCRIPTS/ is recommended.
If One-Time Script is placed in special folder /SCRIPTS/TOOLS it will be visible in EdgeTX RADIO>TOOLS tab
To give this One-Time Script unique name place at the beginning of lua script line:
-- toolName = "TNS|ScriptName|TNE
Otherwise script's filename will be used to display in RADIO>TOOLS list.
Wizard scripts must be stored in the same subfolder of /TEMPLATES/ with the same "first name" as the template file using it. Some Wizard scripts are just small scripts that load one of the common scripts located in /SCRIPTS/WIZARD/.
Interface
Every script must include a return
statement at the end, defining its interface to EdgeTX. This statement returns a table with the following fields:
Field | Type | Required | Desctiption |
---|---|---|---|
run | function | Function is called periodicaly when script is running. |
Parameters
event number | Used to indicates which radio key has been pressed (see Key Events) |
touchState table | This parameter is only present when radio is equiped with touch interface and |
Return values
exit multi type |
|
Field | Type | Required | Desctiption |
---|---|---|---|
init | function | This function is called once when script is executed |
Parameters none
Return Values none
Examples
Simplest one-time LUA script
Because 0 is returned all the time this script will continue running until user long press EXIT (RTN) key.
One-Time LUA script with initialization and exit feature if user short press and release EXIT (RTN) key