Page 1 of 1

Simple debugging functions

Posted: Wed Jan 16, 2013 3:47 pm
by demonnic
I honestly can't claim I created these, but I can't remember who it is gave them to me originally either. I do recall he told me I could distribute it about though, and it's been included in most of my packages (since I use it while writing them) for some time now. I thought it might be a good idea to go ahead and post it up though.

Three aliased commands are available:

debug: toggles debugging on and off
debug list: shows a list of all categories of debugging you are watching
debugc category: will add category to the list of watched debuggers. If it's already on the list, it will remove it. If no category is given, it behaves as "debug list" .

So for example if I am working on an autosipper, and am trying to debug it, I might do

debugc sipper
debug

To add the sipper category to the list of watched items, then toggle debug on. Then in my code, it may look something like this (replacing ... with relevant code):
Code: [show] | [select all] lua
if myHealthPerc < sipHealthPerc then
  demonnic:printDebug("sipper", "Uh oh, health is low. Time to sip!")
  ...
end
And it will print a debugging message to the main window when it passes that branch in the code. If you pass a string or a number, it will echo it to the main window. If you pass a table for the second parameter to printDebug, it will run it through display().

And that's pretty much it in a nutshell. Package is attached, let me know if you have any questions.

Re: Simple debugging functions

Posted: Wed Jan 16, 2013 5:39 pm
by Lezard
This will be very helpful :) thanks for sharing this, and thanks to whomever created it

Re: Simple debugging functions

Posted: Wed Jan 16, 2013 5:56 pm
by kevutian
Yeah, I have been using these functions for years. Really useful.