View Single Post
# 9 02-06-2003 , 12:28 PM
mark_wilkins's Avatar
Registered User
Join Date: Jan 2003
Posts: 161
MEL does not force you to declare variables before using them. If you use a variable without having declared it, Maya will infer from the context what the data type is. After that, it must be used as that data type.

There are several reasons to declare variables whenever you can:

* Declaring a variable forces you to determine what the variable's data type actually should be.

* If you rely on the variable's first use to fix its data type without declaring it, you can run into nasty problems where you can't find where its data type is getting chosen, and your script crashes.

* since often a variable's first use is an assignment, that can be combined with a declaration without cluttering up the code.

In this instance I didn't declare $curr_sel to save a line of code. While it's best to declare variables before using them for the above reasons, variables used within loops are the least offensive context for this because the type is usually obvious.

-- Mark


Mark R. Wilkins
author of MEL Scripting for Maya Animators
www.melscripting.com