Script Debugging (XSISDK)

Table of contents

External Script Debugger

Script Debugger Walkthrough

Debugging Techniques

Even in real production scripts many of the script bugs are simple errors that sometimes are hard to spot by visual inspection. So the vast majority of bugs that appear in your code as you develop can be quickly discovered and fixed using techniques such as those demonstrated in the Script Debugger Walkthrough.

Here are some other thoughts:

Rapid Write/Debug iterations

The Script Debugger Walkthrough shows the concept of concept of debugging your script incrementally as it is being written. Rather than writing what a huge 1000+ line script file all at once, the script is being written bit by bit, with testing and debugging as each few lines of code are added. This quick iteration technique is a question of taste, but it can actually reduce the overall amount of time spent debugging. This technique takes advantage of the very fast development iterations that are possible when using a scripting language in the XSI environment (things have come a long way from the days of punch cards....).

Stepping through the code

Another technique is very simple - just step through your script even before you know whether you have bugs or not. By watching the new script code execute line by line you will quickly know if it is behaving in the way that you expect or whether it is full of logic errors. It's basically the idea of assuming that your new script code is going to contain bugs, rather than assuming it is perfect right off the bat. If you are like any normal programmer your initial code will contain many bugs and your real challenge is to iron out the flaws so that it is perfect by the time you put it into production.

With the debugger you can even change the values of variables on the fly to test different code paths or inputs. For example you can test error messages that are hard to reproduce.

Try Catch

The JScript "try...catch" statement is a great way to make scripts that are more robust. However it can also make it harder to debug the script, because any runtime errors will be absorbed. To debug code protected by a try...catch you may need to temporarily comment out the try...catch. However you can also use the "debugger" statement as shown in the previous Logic example, so that you can step through the code line by line to see where it suddenly jumps to the "catch" statement.

Ask a friend

If you get stumped with a bug ask someone else to take a look - sometimes they will something easily because of the fresh perspective. If no one is available take a break and look at the code later on, e.g. the next morning. A bug that seems impossible to track through bleary eyes at 1AM may be totally obvious after a good night's sleep.

Unit Testing

A lot of XSI plug-ins are rapidly developed pipeline solutions, with a short life time. But it is also possible to write high quality commercial-grade software on top of the XSI SDK. As the size of the project gets large the use of professional software development techniques gets more valuable. These topics are beyond the scope of the XSI wiki and well documented elsewhere, but it is worth mentioning that techniques like Unit Testing, Abstraction, Encapsulation, Object-Orientation and robust error handling are all possible even with languages like JScript.

Debugging - Art or Science

Even an script debugger cannot directly tell you what the bugs in your code are. It is just a tool to help answer questions about what is going on inside a script. Debugging is a skill, some might say an art. Some developers are really good, but by learning techniques and getting lots of experience it will get easier.

This page was last modified 07:57, 31 Aug 2007.
This page has been accessed 5965 times.

© Copyright 2009 Autodesk Inc. All Rights Reserved. Privacy Policy | Legal Notices and Trademarks | Report Piracy