A Lua script stopped with an error
What ArduPilot says:
- Error: …
- Unable to load the file: …
- Unknown error (N) loading …
- Engine Error: …
- Lua: …
- … did not return a delay (0xN)
Also explained here: 3 more
- Panic: …
- … did not return a function (0xN)
- … returned bad result count (N)
Script errors reach you as “Lua: …”, usually with the file name and the line number. “Error: …” means the file could not even be read as Lua (a syntax error); other texts are errors met while running. “did not return a function”, “did not return a delay” and “returned bad result count” mean the script's update function did not end the way ArduPilot expects: with the function to call next and the delay in milliseconds. The failed script is removed and not run again; the others carry on. The line is repeated every 10 seconds, ten times.
What to do, most likely first
The script was written for another firmware version, and a function it calls has changed or is missing.
CheckThe text says “attempt to call a nil value” or “bad argument”, with a line number.
FixTake the script from the same version as your firmware; the Lua Applet Catalog lists every applet per version.
The script needs something that is not there: a module file, its own parameters, a device.
Check“module … not found” means a file is missing from APM/scripts/modules. Read the applet's own instructions for the parameters it expects.
FixCopy the modules next to the script, set the parameters it asks for, and reboot.
A mistake in your own script.
CheckGo to the line number in the message.
FixCorrect it and reboot or restart scripting. An update function must end with a line like “return update, 100”.
“Panic: …” (4.6) and “Engine Error: …” (4.7) are errors in the engine itself, outside any one script. 4.6 throws all scripts away and loads them again from the start; 4.7 ends the engine, and “Scripting: stopped” follows.
Parameters to look at
| Parameter | What it is |
|---|---|
SCR_ENABLE | Enable Scripting |
SCR_DEBUG_OPTS | Scripting Debug Level |
Where to do it:Lua Applet Catalog
The code that sends it
Error: …
libraries/AP_Scripting/lua_scripts.cpp lua_scripts::load_script() · Open in ArduPilot Copter-4.7.1
Unable to load the file: …
libraries/AP_Scripting/lua_scripts.cpp lua_scripts::load_script() · Open in ArduPilot Copter-4.7.1
Unknown error (N) loading …
libraries/AP_Scripting/lua_scripts.cpp lua_scripts::load_script() · Open in ArduPilot Copter-4.7.1
Engine Error: …
libraries/AP_Scripting/lua_scripts.cpp lua_scripts::run() · Open in ArduPilot Copter-4.7.1
And 5 more messages, sent from the same places.