SimplyMaya Forums

Welcome to the forum, feel free to ask questions here.

Home / forum / Animation / Mel Scripts & Programming / passing a variable to a proc
Register FAQ Members List Calendar Mark Forums Read

New Thread
 
Thread Tools
Old 24-02-2004, 11:42 PM   #1
Dann
Registered User
 
Dann's Avatar
 
Join Date: Feb 2003
Location: Los Angeles
Posts: 695
Thanks: 0
Thanked 2 Times in 2 Posts
Question 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
}
Dann is offline   Reply With Quote
Old 25-02-2004, 11:37 AM   #2
Alan
Moderator
 
Alan's Avatar
 
Join Date: Oct 2002
Location: London, UK
Posts: 2,800
Thanks: 0
Thanked 5 Times in 5 Posts
Default

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
Alan is offline   Reply With Quote
Old 25-02-2004, 03:35 PM   #3
Dann
Registered User
 
Dann's Avatar
 
Join Date: Feb 2003
Location: Los Angeles
Posts: 695
Thanks: 0
Thanked 2 Times in 2 Posts
Default

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?
Dann is offline   Reply With Quote
Old 25-02-2004, 03:53 PM   #4
Alan
Moderator
 
Alan's Avatar
 
Join Date: Oct 2002
Location: London, UK
Posts: 2,800
Thanks: 0
Thanked 5 Times in 5 Posts
Default

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
Alan is offline   Reply With Quote
Old 25-02-2004, 04:06 PM   #5
Dann
Registered User
 
Dann's Avatar
 
Join Date: Feb 2003
Location: Los Angeles
Posts: 695
Thanks: 0
Thanked 2 Times in 2 Posts
Default

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.
Dann is offline   Reply With Quote
Old 25-02-2004, 04:35 PM   #6
Alan
Moderator
 
Alan's Avatar
 
Join Date: Oct 2002
Location: London, UK
Posts: 2,800
Thanks: 0
Thanked 5 Times in 5 Posts
Default

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
Alan is offline   Reply With Quote
Old 25-02-2004, 06:01 PM   #7
Dann
Registered User
 
Dann's Avatar
 
Join Date: Feb 2003
Location: Los Angeles
Posts: 695
Thanks: 0
Thanked 2 Times in 2 Posts
Default

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, 15 views)
Dann is offline   Reply With Quote
Old 26-02-2004, 10:35 AM   #8
Alan
Moderator
 
Alan's Avatar
 
Join Date: Oct 2002
Location: London, UK
Posts: 2,800
Thanks: 0
Thanked 5 Times in 5 Posts
Default

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!!
__________________
Technical Director - Framestore

Currently working on: Your Highness

IMDB
Alan is offline   Reply With Quote
Old 26-02-2004, 04:53 PM   #9
Dann
Registered User
 
Dann's Avatar
 
Join Date: Feb 2003
Location: Los Angeles
Posts: 695
Thanks: 0
Thanked 2 Times in 2 Posts
Default

That is very stupid. I never would have figured that out.

Thanks for all the help Alan.
Dann is offline   Reply With Quote
Old 26-02-2004, 05:35 PM   #10
Alan
Moderator
 
Alan's Avatar
 
Join Date: Oct 2002
Location: London, UK
Posts: 2,800
Thanks: 0
Thanked 5 Times in 5 Posts
Default

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..


Alan
__________________
Technical Director - Framestore

Currently working on: Your Highness

IMDB
Alan is offline   Reply With Quote
New Thread

« Previous Thread | Next Thread »

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

1 Month

$34

Month-to-month billing
$34/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
 
 

3 months

$87

Billing every 3 months
$29/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
Save $5 per month or $15 in total compared to monthly billing with this package.

12 months

$288

Billing every 12 months
$24/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
Save $10 per month or $120 in total compared to monthly billing with this package.

Your plan will automatically renew. You can cancel at any time via your PayPal account to avoid being charged again.

You can view the FAQ on our video plans here. You can contact us directly here. By clicking one of the buttons above, you agree to our Terms and Privacy Policy.