I've attached my debug include file. You can use it outright, or take ideas from it. It writes to a debug.txt file in the media folder (writeable media folder in Appdata folder). You need to:
#include "debug.agc"
Then
debugStart()
in your main code to kickstart the module. Wherever you want to output information to the log use:
DebugWrite("MyVariable = " + MyVariable$)
If your program is crashing, use
DebugWriteSave()
This ensures the text is saved to the file, otherwise it may not write it before the crash.
Use:
DebugSave()
to save at regular intervals (slow, so don't use everywhere)
Use:
DebugWriteConsole()
to write to the screen. This is for slow-moving output. If you write to it every cycle, it will just be a blur of unreadable information. If using the console, then before every sync(), call:
DebugOutputConsole()
Quidquid latine dictum sit, altum sonatur