Beer glass scene creation
This course contains a little bit of everything with modeling, UVing, texturing and dynamics in Maya, as well as compositing multilayered EXR's in Photoshop.
# 1 25-02-2004 , 12:42 AM
Dann's Avatar
Registered User
Join Date: Feb 2003
Location: Los Angeles
Posts: 695

passing a variable to a proc

I'm trying to pass a variable from one proc to another, but can't figure out the syntax. I can't seem to find the place in the docs where this would be described. Can anyone help?

Something like this.

global proc testPrint()
{
string $sendA = "Success";
string $sendB = "Failure";

printMe($sendA,$sendB);

}
global proc printMe(string $A, string $B)
{
print $A
print $B
}

# 2 25-02-2004 , 12:37 PM
Alan's Avatar
Moderator
Join Date: Oct 2002
Location: London, UK
Posts: 2,800
Try this

proc alanTest(string $a, string $b)
{
print ("a: "+$a+"\n");
print("b: "+$b+"\n");
}
alanTest("alan", "woods");
You have to make sure that you pass a string and that when you print it that you concatenate it properly so that it is evaluated and not printed as a literal.

Alan


Technical Director - Framestore

Currently working on: Your Highness

IMDB
# 3 25-02-2004 , 04:35 PM
Dann's Avatar
Registered User
Join Date: Feb 2003
Location: Los Angeles
Posts: 695
Alan,

Thanks for all the help. I'm not actually trying to print something, I was jus using that as an example. What I'm trying to do is not pass a string from opne proc to another, but pass a viriable. I'm not sure why I can't do it, as my test looks just like your to my eyes. What's the diff?

# 4 25-02-2004 , 04:53 PM
Alan's Avatar
Moderator
Join Date: Oct 2002
Location: London, UK
Posts: 2,800
you can do this with any variable (A string is a TYPE of variable). so

proc intTest(int $a, int $b)
{
int $c = $a + $b;
print ("value of c is: " + $c + "\n");
}

intTest(4,5);

That should work.


Technical Director - Framestore

Currently working on: Your Highness

IMDB
# 5 25-02-2004 , 05:06 PM
Dann's Avatar
Registered User
Join Date: Feb 2003
Location: Los Angeles
Posts: 695
right, but why can't I do this...

proc intTest(int $a, int $b)
{
int $c = $a + $b;
print ("value of c is: " + $c + "\n");
}

int $c = 4;
int $d = 5;
intTest($c,$d);

That should work as well, but it doesn't. I get the message varible $a is not defined.

# 6 25-02-2004 , 05:35 PM
Alan's Avatar
Moderator
Join Date: Oct 2002
Location: London, UK
Posts: 2,800
it does work, you need to make sure that the function is properly defined before you use it. So highlight the functino and then hit the small enter key on your keyboard and it should appear in the top half of the window. Then execute the other half of the script and it should work fine. I copied and pasted it straight in and it worked


Technical Director - Framestore

Currently working on: Your Highness

IMDB
# 7 25-02-2004 , 07:01 PM
Dann's Avatar
Registered User
Join Date: Feb 2003
Location: Los Angeles
Posts: 695
OK, this is pissing me off!! That DOES work, but my script still doesn't. It turns out, my script doesn't understand my variable, says it's not defined, but it sure as hell is! Can someone take a look at my script and tell me why $overscanStart thinks itself to be undefined!?!

Many thanks in advance for the kind soul who solves this for me.
-dann

Attached Files
File Type: mel filmoffset.mel (3.3 KB, 241 views)
# 8 26-02-2004 , 11:35 AM
Alan's Avatar
Moderator
Join Date: Oct 2002
Location: London, UK
Posts: 2,800
right the problem is that you are not evaluating that variable to it's value. Basically the way I have fixed it is to build up a string of the command (as that is what -c is expecting)

so you have

string $com = "resetCamera("+$cameraStartOverscan+")";

then in the button put -c $com and that should work fine.

Bloody mel it's so stupid sometimes!!
user added image


Technical Director - Framestore

Currently working on: Your Highness

IMDB
# 9 26-02-2004 , 05:53 PM
Dann's Avatar
Registered User
Join Date: Feb 2003
Location: Los Angeles
Posts: 695
That is very stupid. I never would have figured that out.

Thanks for all the help Alan.

# 10 26-02-2004 , 06:35 PM
Alan's Avatar
Moderator
Join Date: Oct 2002
Location: London, UK
Posts: 2,800
anytime, there's probably a better way of doing it, but that will work. What you could do is build a string of the whole button command in a similar way to what I showed you and then do that. It's the same things really though..

user added image
Alan


Technical Director - Framestore

Currently working on: Your Highness

IMDB
Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads