So what are the general thoughts on global variables with MEL?
I think the main issue with them is that they can be altered by other scripts if you're not carefull with how you name them. For example $x for a global var name is too simple. I guess also that they exists and take memory until youzero them but then they name of the global var is still in memmory until you exit Maya.. which can become a pain while testing.
Ideally you would pass variables from one procedure to another using the paramter and return values of a proc. I find that this makes your script more modular and easier to read.
It's good coding practice to break your script up into little procedures rather than to try to do it all in one global proc.
In the script I posted as a response to the original message I did in fact imply to use a global variable.. or at least that why that script didn't work.
The appropriate method would be as follows.
//---------------------begin
string $test;
$test=Blender(1,"hello");
print $test;
global proc string Blender(int $Blend,string $blendName){
string $testing;
$testing="";
print($testing+"-n");
if ($Blend ==1){
$testing=$blendName;
}
return $testing;
};
//----------------------end
I don't think that there is so much a right and wrong way to write a MEL script but you do want to adopt habits that will make it easier for you to write them and read them. Making your code modular will allow you to keep snipets of code that you can paste into new scripts so that you don't have to rewrite ever line for mundane functions for every script.
If the code works wear it.
---a note from our sponsor---
Have you tried searching highend3d?
www.gmask.com