MEL Troubleshooting

From TOI-Pedia


When you're just starting with MEL scripting, the dozens of errors that you may get - some pretty straightforward, others very cryptic - may be discouraging. This page aims to help you troubleshoot and solve the most common MEL scripting errors. But hang in there, don't let a few errors discourage you: you're way smarter than that stupid computer, you just need to work out a way to communicate with the rigid machine.

To be able to quickly localize errors, enable Line numbers in error messages.

In the Script Editor: History > Line numbers in errors.

Note that Maya reports where it detects the syntax error. The (root) cause may very well be in the line above or even many lines earlier in the script.

When you encounter multiple errors, start with the first encountered error.

Syntax Errors

Probably one of the most occurring type of errors, often caused by stupid typos. Don't worry; even experienced programmers/scripters regularly have to fix their script because of simple parse errors.

  • Make sure every command ends with ;
  • Make sure all brackets and curly brackets ({}) match [1]

'This procedure has no return value'

Your procedure contains a return statement, but the procedure declaration doesn't specify a return value. Add a return value specification to the procedure declaration or remove the return statement.

'Procedure is missing a return statement'

You specified the procedure to have a return value, but the procedure doesn't contain a return statement. Either remove the specification of a return value in the procedure declaration, or add a return statement to your procedure.

Variable Types

'Invalid redeclaration of variable ... as a different type'

You've declared (explicitly or implicitly) a variable as a certain type and are now trying to declare/use it as a different type. This is not allowed in Maya (for global variables). Restart Maya to make the previous declarations disappear, or use a different variable name.

'Cannot cast data of type ... to ...'

Your trying to cast array data into a non-array variable, or vice-versa. Or you are assigning an array of one type to an array of another type (eg: a float array into an integer array)

Semantic Problems

My (mathematical) division doesn't give the right result

You must be very careful when calculation float values using divisions. Take the following example:

float $a;
$a = 1 / 2;

One would say the result, the value of $a, should be 0.5. All seems fine, $a is declared as an float, so no problem there. But there is a catch when executed:

float $a;
$a = 1 / 2;
// Result: 0 //

The result is 0. This seems wrong, but there is a certain logic to it. You're asking to divide two integers and then assign the outcome to a variable $a. It's this two-stage execution that causes the problem. When dividing two integers, MEL assumes the result to be an integer as well. As the integer cannot hold any decimals, they are lost, so 0.5 results into 0. This value is then assigned to the variable $a.

The solution is to force MEL to use floats in the calculation in the first stage, by forcing a typecasting of one of the two integer values:

float $a;
$a = float(1)/2; //use the float() command to force the value to be interpreted as a float
// or:
float $a;
$a = 1.0/2; //by specifying 1.0 instead of 1, a float is used

Maya hangs or crashes when executing my script

You should very carefully inspect the loops in your script. Probably one of the loops never finishes:

For loops:

  • Make sure the condition is correct. For instance: make sure you didn't write a condition that assumes decreasing values, while the iteration specifies an increasing value:
for ( $i=10; $i > 1; $i = $i + 1) {
//this will be an endless loop.
//$i will always be larger than one, as the value only increases...
  • Make sure the counter value isn't modified within the loop so that the condition is always met.

While loops

  • Make sure you have a statement within the loops that causes the condition not to be met at a certain point. With While-loops it's easy to forget to add the increment for a count for instance.

Also check that you don't have problems related to #My (mathematical) division doesn't give the right result

Interface / Layout problems

'Too many children in layout ...'

You're trying to add too many controls to a layout. Make sure you didn't forget a setParent somewhere to get back to a higher hierarchy.


  1. It's recommended to use a proper editor, such as Crimson Editor or Notepad++, that can help you to find corresponding pairs of brackets.
Personal tools