Toggle debug print in Maxscript
Printing out a debug spew is very useful when scripting, but often you end up with tons of print statements littering your code. Printing debug is often one of the slowest things in max (or any language, instead of just doing the actual work you are sending signal through hardware, but I digress). Often you’ll only want to turn toggle on the debug logging when you’ve got an issue.
A while ago I started using a more clever system by setting a variable debugprint = true at the top of my scripts. Then when I was using the debug spew I’d use:
if debugprint == true then print "My debug stuff"
Matt (who I work with) came up with a much more elegant solution. Much like my debugprint = true variable he created debugPrintVal, and instead of querying the state of it for every print, he simple used a new function, debugPrint:
fn debugPrint printStr =
(
if debugPrintVal == true do
(
Print printStr
)
)
So, instead of using :
if debugprint == true then print "My debug stuff"
We can now used the much cleaner version:
debugprint "My debug stuff"
July 25th, 2011 at 8:28 pm
That’s a really good idea!
August 2nd, 2011 at 5:33 pm
I implemented a similar system that indents processes as they run it was mel..
This would log effectively stack traces, you could use the dInits to trip a debug dump of current state if you went a certain direction in code you weren’t expecting.. made working with me infinitely quicker.
Using a combination of:
dInit
dStart
dPrint
dPrintArray
dEnd
dReset
would give you:
{ *************We have lighting data to add ************ Contents of: $cmds lightingChunkGroupVis ( 1, "ff_interior_lightingData" ) lightingChunkGroupVis ( 0, "ff_interior_lightingData" ) createDialOutGui { Frame_ff_interior_lighting } createLevelChunkButton { Creating button for: x_FrostFire --> ff_interior_sh parentUi --> ff_interior_lighting_column ff_interior_sh_visCheckBox chunkButtonStates { ff_interior_sh } } lightingDataUiVisability { currentWorkSpace { } getSceneRefList { in getAtgiLevelReferenceNodes { } } levelDialOutStates { lighting-> } setLightingChunkVis { getLightingChunkReferences { $chunk --> Contents of: $lightingChunks getSceneRefList { in getAtgiLevelReferenceNodes { } } } Contents of: $allLightingChunks ff_interior_sh $lchunk ->ff_interior_sh $visCheckBox ->ff_interior_sh_visCheckBox showChunk { whichNode { } } }August 2nd, 2011 at 5:34 pm
Of course if your site maintained the indentation the dump at the bottom would be tabbed as the code stepped in and out of procs
August 4th, 2011 at 9:10 pm