Bitfighter  021
The Bitfighter Lua Documentation - Robots, Levelgens, and Plugins
Debugging Tips

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!")

Other tricks:

There are a couple of other ways to get info out of a script. None of these are appropriate for long term usage, but they do work well for quick and dirty debugging.

Bots can print short messages to the global chat like so:

bot:globalMsg("Status " .. status)
bot:privateMsg(message, "ChumpChange") -- If you know your player name!

Levelgens can do this as well, or print short messages by setting the announcement message:

levelgen:globalMsg("success!")
levelgen:announce("I'm at: " .. p.x .. "," .. p.y)
levelgen:privateMsg(message, "ChumpChange") -- If you know your player name!