PDA

View Full Version : Passing variables into another procedure


joeyipextra
01-14-2011, 05:38 PM
Hi, I'm trying to call a procedure from another script while passing a variable with it. This works if the variable is explicitly declared. However, it seems if my variable has a definition, Maya returns an Error: "$name" is an undeclared variable. Perhaps this is because $name is not a global variable, and hence, when passed to ChrSetup(), $name becomes undeclared? In that case, how do I make $name a global value (since it is not a constant)? Otherwise, how else can I pass this variable?

$CharName = `textFieldGrp -label "Character Name:"`;
string $name = `textFieldGrp -q -text $CharName`;
button -label "Apply" -command "ChrSetup($name)"; //sourced from ChrSetup().mel

Thanks!
Joe

NaughtyNathan
01-14-2011, 08:15 PM
this is purely down to string/variable catenation. anything you put INSIDE "" is a literal string, and what you usually want to do in these situations is not put the literal string "$variable" into your string, but to add it's contents to the rest of your string. you do it like this:

button -label "Apply" -command ("ChrSetup " + $name);always surround your string catenations in (braces) and just for clarity/simplicity sake, in MEL you don't need to use the () on a function call.

myFunc("pCube1"); // is exactly the same as:
myFunc pCube1;
myFunc "Naughty Nathan"; // your string may need "" if it contains spaces
:nathaN

joeyipextra
01-14-2011, 08:34 PM
Thank you! that is a much cleaner approach to passing arguments, and won't require global variables. However, with this concatenation, what is the syntax for passing multiple variables?

joeyipextra
01-14-2011, 08:36 PM
Ahh got it. It is just spaces in between (I thought I needed a comma at first)

Thank you!

CGTalk Moderation
01-14-2011, 08:36 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.