Simply Maya User Community

Simply Maya User Community (https://simplymaya.com/forum/index.php)
-   Programming (https://simplymaya.com/forum/forumdisplay.php?f=32)
-   -   passing a variable to a proc (https://simplymaya.com/forum/showthread.php?t=10604)

Dann 25-02-2004 12:42 AM

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
}

Alan 25-02-2004 12:37 PM

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

Dann 25-02-2004 04:35 PM

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?

Alan 25-02-2004 04:53 PM

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.

Dann 25-02-2004 05:06 PM

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.

Alan 25-02-2004 05:35 PM

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

Dann 25-02-2004 07:01 PM

1 Attachment(s)
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

Alan 26-02-2004 11:35 AM

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!!
;)

Dann 26-02-2004 05:53 PM

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

Thanks for all the help Alan.

Alan 26-02-2004 06:35 PM

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


All times are GMT. The time now is 01:58 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Simply Maya 2018