One of the most serious script writing issues that I have run into is mixing the code that performs the work with the UI the scripter wrote. Its pretty clear from most of the examples I have seen of this that the person writing the script was going along and and all of a sudden realized that they needed to ask the artist to give them some important information. Right there in the middle of their code they will pop up a dialog asking for the necessary information. Even worse they will actually query the UI element in the middle of some other function performing the work.
Why is this a problem? Well what if you want to batch process this function. The dialog will be popped up every time you go through the lop requiring artist input even if its the same value every time. Another thing to consider is if you want to modify the function you might have references to UI objects scattered through the code that may or may not exist at the time you need to get the value.
Instead write your code that actually does the work as a stand alone function that has parameters passed into it for all the information it needs to perform its function. This does one very important thing, it separates the code functionality from how it gets the values it needs. This separation means that if you need to re-factor the code you will not have to worry if UI widget exists that has the value you need. It also allows you to use the code in other processes, for example batching.
This way you could have two different ways for the artist to perform the same function, one would be hooked up to a UI that would collect all the information to run the function and call it when the user hits the Okay button. The other could be a batch script that determines the values somehow and runs the function on a collection of objects or files with no human intervention.
The important concept is to separate the desired functionality from how you actually get the information you want the function to use.
Post a Comment