PDA

View Full Version : Procedure question...


alesmav
09-19-2003, 02:25 PM
I am building my UI and I encountered the following problem.
As you all know when building UI, you have to call procedures.

Lets say we have a simple UI with two buttons. With the first button you call a procedure in which you declare a float variable and assign a value to it. Now I want the second button to call the procedure that does something with this variable. When executing the script maya says that the variable from the second procedure is undeclared. I then declared a variable a a global, but it still doesn't work. What am I doing wrong??

ALES

Buexe
09-19-2003, 02:34 PM
Did you declare the global variable in both variables? If not you should, because Maya does not automatically recognize it when you use it in another proc

global proc name1 ()
{

Buexe
09-19-2003, 02:37 PM
Sorry I accidentally hit the submit reply button before finshing my last post. To make the variables visible in both procs use this scheme:

global proc name1 ()
{
global float $globy1;
$globy1 = "hello there!\n":
}

global proc name2 ()
{
global float $globy1;
print $globy1;
}

Cheers
buexe

mhovland
09-19-2003, 04:48 PM
Of course if you execute the code, you might want to assign a float value to the float variable, instead of the string :thumbsup:

global proc name1 ()
{
global float $globy1;
$globy1 = "3.1416":
}

global proc name2 ()
{
global float $globy1;
print $globy1;
}

Buexe
09-19-2003, 05:09 PM
good point!:D

alesmav
09-20-2003, 09:14 AM
Now I get it... You have to make both, procedure AND variable global. I just did a variable global.


Thanks a LOT!!

ALES

mhovland
09-20-2003, 04:14 PM
You are correct. Any procedure that is called from a button press has to be global. Just another one of the basic rules of MEL.

CGTalk Moderation
01-16-2006, 04:09 AM
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.