Home TI-Nspire Authoring TI-Nspire Scripting HQ Scripting Tutorial - Supplement: Working with Scripts on the iPad


Scripting Tutorial - Working with Scripts on the iPad

Download this page in PDF format

Texas Instruments TI-Nspire Scripting Support Page


Working with Scripts on the iPad

In most respects, working with TI-Nspire on the iPad is a wonderful experience. However, without a Script Editor for this platform, debugging scripts can be a frustrating and even painful experience. The lack of a console denies the author that vital information which allows errors and bugs to be tracked down and corrected.

The solution to this problem lies in making available, within the iPad platform, that vital current information concerning the running script. The code shown here allows any errors to be logged, stored to a running variable, and then passed on - in many (but not all) cases, this code may rescue your script from a fatal crash and allow it to continue running. This is a useful feature for scripts on any platform, and so you may choose to include this code snippet at the start of all your scripts, as I do these days.

This method makes use of the command platform.registerErrorHandler( which, as advertised, registers errors, and makes available four key pieces of information:

  • lineNumber,

  • errorMessage,

  • callStack, and

  • locals

These are strung together and stored as a variable, which may then be displayed in a MathBox on a Notes page.

Having access to errors and other script information directly on the iPad should make debugging your scripts much easier. I use this method in conjunction with a DropBox folder, open on both my computer and my iPad App. In this way, I can immediately edit my script on the computer, close and re-open on the iPad and test without delay.

platform.apilevel = '2.5'

screen = platform.window
w = screen:width()
h = screen:height()

-- Logging -------------------------------

local msgStr = ''
local msgs = { }
local myError = ''
var.store("err_messages", msgStr)

local function addMsg(msg)

table.insert(msgs, msg)
msgStr = msgs[1]
for m = 2, #msgs do

msgStr = msgStr..string.char(10)..msgs[m]

var.store("err_messages", msgStr)


platform.registerErrorHandler(function(lineNumber, errorMessage, callStack, locals)

print("Errors: ", lineNumber, errorMessage, callStack, locals)
myError = msgStr..string.char(10).."Errors:"
return true


Back to Top


Home TI-Nspire Authoring TI-Nspire Scripting HQ Scripting Tutorial - Supplement: Working with Scripts on the iPad