Some simple but useful debugging tips

Blitz3D Forums/Blitz3D Tutorials/Some simple but useful debugging tips

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Without reading the article here's a couple of debug methods I use:

Messages:
Put messages in your code. If you don't know where things are going wrong create a breakpoint function. Something like;
function BreakPoint(message$)
cls
print message
waitkey
end function

This if you really can't work out where your code is going wrong you can throw messages in all over your code and see at what point it breaks.

Visible Debug Stuff:
Create a whole debug library that allows you to draw lines, messages, circles, whatever, the alien breed has a good example of a debug library (even though I say so myself!) which allows you to if you have debug mode (global variable) switched on various debug stuff gets added to the screen, this way you can sort out what everything is doing and maybe work out why your AI is going mental.
The debug stuff is then drawn after everything else so it's always visible.

Indent:
If you don't indent your code you're a fool! So many "This bloody thing won't compile" problems are due to a stray endif or next. Indent your code and it is clear where your code is going wrong.

Complex If statements:
If a>0 and b<0 and b>50 or c>20 and d<9 etc etc etc then...
These go wrong very often because of the way a particular language vaidates this stuff. Quite frankly do nested ifs, I've speed checked this stuff and there's shag all in it and it makes your code much more readable. Also, test your 'if' in a standalone piece of code to see if it does what you expect it to do.

Comment:
I know it's a pain but do it.