View Full Version : Derive variable from another MEL Script?
H2o-KiD 08-25-2011, 08:26 PM Heya guys... this might be a newbie question but how do I get a variable value from another MEL?
For example the value of $haha might varies base on what I do in MEL A and gets recognized in MEL B without MEL B giving me "Undeclared variable" error.
Thanks and have a goody daydy~! :)
|
|
Mondo
08-25-2011, 10:14 PM
Look into the "source" command. As long as your initial variable is declared outside of a procedure and melA is sourced in melB - you're good to go.
Are MEL A and MEL B in separate files?
Is $haha declared in a proc?
Could you post an example?
cupy
jaydru
08-26-2011, 11:30 AM
you could make the var global, might not be the best thing to do though, can you not return the value from the first proc?
H2o-KiD
08-26-2011, 12:34 PM
Yes, MEL A and B is seperate files.... and I sorta worked it out for now using global variable..
MEL A
global proc leftIKControl(string $shortName)
{
menuItem
-label "Follow Head"
-radialPosition "N"
-command ("global int $chosenWeight = 0; dynamicParent;");
menuItem
-label "Follow Torso"
-radialPosition "E"
-command ("global int $chosenWeight = 1; dynamicParent;");
menuItem
-label "Follow Hip"
-radialPosition "E"
-command ("global int $chosenWeight = 2; dynamicParent;");
}
Note that in the command I call global variable global int $chosenWeight = X
then for MEL B...
global proc dynamicParent()
{
if ($chosenWeight == 0)
{
;
}
else if ($chosenWeight == 1)
{
;
}
else if and so on...
}
also please note that I am a newbie and you guys might have better and cleaner solution as I have now or this is perfect fine...
cupy : Is $haha declared in a proc
- What do you mean by this can you clarify this or give more insight on how about doing it this or show an example?
jaydru : you could make the var global, might not be the best thing to do though, can you not return the value from the first proc?
- Why you'd say global var might not be the best thing to do... more insight or an example of how I can return the value from the first proc?
Thanks a bunch guys, your helps are really helpful!.
I meant like the following example demonstrates:
string $outProcVar = "I'm out of the proc" ;
global proc myProc()
{
string $inProcVar = "I'm in the proc";
}
//You can access $outProcVar because print() will be called from the same scope
print($outProcVar);
//This would give you an ERROR, becouse $inProcVar is a local variable and only accessable inside the procedure:
//print($inProcVar);
And I also agree with jaydru's answer, that in programming it is not nice to give access to any variables. This link about ecapsulation will give you an idea about it:
LINK (http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming))
cupy
In your case I would do something like this:
MEL A:
int $chosenWeight = 0
global proc leftIKControl(string $shortName)
{
menuItem
-label "Follow Head"
-radialPosition "N"
-command ("$chosenWeight = 0; dynamicParent;");
menuItem
-label "Follow Torso"
-radialPosition "E"
-command ("$chosenWeight = 1; dynamicParent;");
menuItem
-label "Follow Hip"
-radialPosition "E"
-command ("$chosenWeight = 2; dynamicParent;");
}
MEL B: remaining the same
You must run MEL A before MEL B!
cupy
This colud also help you:
MEL A
global proc leftIKControl(string $shortName)
{
menuItem
-label "Follow Head"
-radialPosition "N"
-command ("dynamicParent(0);");
menuItem
-label "Follow Torso"
-radialPosition "E"
-command ("dynamicParent(1);");
menuItem
-label "Follow Hip"
-radialPosition "E"
-command ("dynamicParent(2);");
}
MEL B
global proc dynamicParent(int $chosenWeight)
{
if ($chosenWeight == 0)
{
print("0");
}
else if ($chosenWeight == 1)
{
print("1");
}
}
cupy
H2o-KiD
08-26-2011, 03:03 PM
I tried the method similar to your first reply, but when I try testing executing it in Script Editor, MEL B for particular, it gives me $chosenWeight is an undeclared variable.
Will it work even if it's like this? Cheers :beer:
Run this in Maya first:
int $chosenWeight = 0
then run this:
print($chosenWeight)
It seems that Maya stores such things...
cupy
H2o-KiD
08-26-2011, 03:40 PM
Yea, it seems to work when they are out of the global proc and gives me undeclared variable if inside global proc. :banghead:
H2o-KiD
08-26-2011, 04:25 PM
global proc leftIKControl(string $shortName)
{
menuItem
-label "Follow Head"
-radialPosition "N"
-command ("dynamicParent(0);");
menuItem
-label "Follow Torso"
-radialPosition "E"
-command ("dynamicParent(1);");
menuItem
-label "Follow Hip"
-radialPosition "E"
-command ("dynamicParent(2);");
}
global proc dynamicParent(int $chosenWeight)
{
if ($chosenWeight == 0)
{
print("0");
}
else if ($chosenWeight == 1)
{
print("1");
}
}
This worked wonderfully.... thank you so much guys! :bounce:
CGTalk Moderation
08-26-2011, 04:25 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.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.