Here's my code. You'll have to add cDEBUG and a couple of global variables that start
g. in my code to make it work.
always call DebugStart() first to set up the system.
DebugSave() and DebugWriteSave() make sure the lines are written to the file before your program crashes. Not a good idea to use this in a tight loop unless bug-searching because it is constantly closing and reopening the file.
DebugWriteConsole writes to the screen. Can be used for slow updates, no good for outputting every program cycle.
` *************************************************************************
function DebugStart()
` *************************************************************************
if g.debug = 1 or cDEBUG = 1
g.debug = 2
g.debugFile = openToWrite("debug.txt",0)
writeLine(g.debugFile, "Debug Started (cDEBUG = " + str(cDEBUG) + ")")
writeLine(g.debugFile," ")
dim arrConsole[50] as string
g.consoleLine = 1
setPrintSize(16)
setPrintColor(232,232,255,212)
debugSave()
endif
endfunction
` *************************************************************************
function debugEnd()
` *************************************************************************
if g.debug = 2
debugWrite(" ")
DebugWrite("Debug ended - Program time " + str(g.time,3) + " Seconds")
closeFile(g.debugFile)
g.debug = 1
endif
endfunction
` *************************************************************************
function DebugWrite(text$)
` *************************************************************************
if g.debug = 2
writeLine(g.debugFile, str(g.time,3) + chr(9) + text$)
endif
endfunction
` *************************************************************************
function DebugWriteSave(text$)
` *************************************************************************
debugWrite(text$)
debugSave()
endfunction
` *************************************************************************
function debugWriteHead(text$)
` *************************************************************************
if g.debug = 2
writeline(g.debugFile,"")
writeline(g.debugFile,str(g.time))
writeline(g.debugFile,"*************************************")
writeline(g.debugFile,"*** " + text$)
writeline(g.debugFile,"*************************************")
endif
debugSave()
endfunction
` *************************************************************************
function debugSave()
` *** @D Files don't get saved until closed. If program crashes, no debug data is available
` *************************************************************************
if g.debug = 2
closeFile(g.debugFile)
g.debugFile = OpentoWrite("\media\debug.txt",1)
endif
endfunction
` *************************************************************************
function DebugWriteConsole(text$)
` *************************************************************************
if g.debug = 2
if g.consoleLine = 50
g.consoleLine = 1
else
inc g.consoleLine, 1
endif
arrConsole[g.consoleLine] = text$
endif
endfunction
` *************************************************************************
function DebugOutputConsole()
` *************************************************************************
for n = g.consoleLine + 1 to 50
print(arrConsole[n])
next n
for n = 1 to g.consoleLine
print(arrConsole[n])
next n
endfunction
Quidquid latine dictum sit, altum sonatur