Debugging Tips

From Bitfighter

Any of your scripts can print a stack trace with the _stackTracer() command (see sample usage below). This will show how you got to a particular execution point, and will print the values of various variables and other potentially useful information. This can be very helpful if there are several conditions under which a function can be called, or why something went wrong.

The print(msg) command will print a message the in-game console (which you can turn on with ctrl+/), and logprint(msg) will print a message to the console, the terminal, and the Bitfighter logfile.

Lua's error command will stop the script, print a message, and cause a stack trace to be printed. Use assert to confirm that a condition is true.

Finally, if you detect an unexpected error condition, you can log a message, trigger a stack trace, and terminate the script with Lua's error function.

logprint("Here's a stack trace:")
logprint(_stackTracer())
if target == nil then error("Have a nil target!") end
assert(target, "Target should never be nil here!")