Can please somebody enlighten me on the following... Flags of many commands seem to require certain data types (linear, double, etc. are mentioned in the Command Reference) that I struggle to find explained in the docs.
// Error: float $gridStep = 100; // // Error: Line 3.22: Invalid redeclaration of variable "$gridStep" as a different type. // // Error: float $beamSize = (1 / $gridStep); // // Error: Line 4.22: Invalid redeclaration of variable "$beamSize" as a different type. //
It works if the problematic data types are declared as integers but this is obviously not acceptable because of the rounding errors.
Well the error says invalid redeclaration. This means it's probably a global variable that you defined earlier, or it's a predefined variable from Maya.
I don't think gridStep is predefined ( it may, but my memory is about as good as a goats ), so you probably had defined $gridStep earlier as a global variable of a different type. probably int since redeclaring it as an int worked.
This is one of the reasons global variables should be avoided if at all possible.
Another thing you may want to consider is you naming conventions... the reason (so I've been told ) most C-like programming languages have all of their functions and keywords with the first letter lowercase and every word after uppercase is so you yourself can be sure of not using a reserved word be declaring variables using an uppercase letter at the begining.
You are right; I have declared those variables before as int's. Realised it myself. This is just a preliminary excerpt from my script; I shall try to sort the global/local declarations as I go along.
It would still be good to know what is the difference between
Data types (int, string, matrix, vector) are explained in the variables section of the maya online docs. Data types of the mel interpreter are very similar (but less robust) to C and C++ variable types, but since there is no struct, char, overloading, etc, it is sometimes far more painful than it should be to actually do things using types ... but i digress... languages like perl don't use variable types, everything is just a scalar...which (maya probably should have just adopted) is much easier to learn, but can be confusing when trying to read and interpret what the program does. The maya interpreter manages alot for you, including memory (no pointers or memory references), but it doesnt know your types, so you have to explicitly declare and pass the correct types- or get an error. Get a good book on C, and read the Mel section of the docs on variables for more of an explanation of types. -erick ps. a good convention for global variables (besides not using them ever) is to name them with really long names, prefixed with a "$G_", like: global string $G_extremelyNecesarry_and_ExposedToTheWorldVariable; This way no one else will redifine your variable, and the same goes for you redefining some one else's variable. Good luck, and avoid global variables.