CGTalk > Software Specific Forums > Autodesk Maya > Maya Programming
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 01-15-2013, 01:38 AM   #1
meldu
PRO
portfolio
osmel briceno carrizo
3D generalist
freelance
caracas, Venezuela
 
Join Date: Sep 2012
Posts: 124
undeclared variable

Hi, good night. I have a problem with a tool that i`m trying to make. The tool is for multiple parent constraints. The tool will have two buttons:

-1 the first one, will define who is the father.
-2 the second button, will define which are the childs, i mean, who will be constrained. And, will constraint this objects to the first one.

So:

1-You select the father, hit the button that says "father"
2-You select the childs, then hit the button that says "sons"

But i get this error:
// Error: "$papa" is an undeclared variable.

This its the script.
//global proc that assing the father

global proc setFather () {
//a variable that search and define who its the father
string $papa[] = `ls -sl`;
print $papa[0];
select $papa[0];

}


//global proc that for the sons

global proc setSons () {

string $sons[] = `ls -sl`;

$myNum = (size(`ls -sl`));

for ($laps = 0; $laps <= $myNum; $laps++){

select -r $papa[0];
select -add $sons
doCreateParentConstraintArgList 1 { "1","0","0","0","0","0","0","1","","1" };

}


}




//main window

window -rtf true -title "multiConstraint" multiCons;
columnLayout;

button -c "setFather" -label "father";

button -c "setSons" -label "sons";

showWindow multiCons;

I think its something about the global variables, but i cant figure out how to do it.

Thanks.
 
Old 01-15-2013, 02:00 AM   #2
gmask
Obfuscator
 
gmask's Avatar
gmask
Power Sitting
Topanga, USA
 
Join Date: Oct 2002
Posts: 6,937
you didn't declare $papa as a global variable
__________________
blah blah blah
 
Old 01-15-2013, 04:08 AM   #3
meldu
PRO
portfolio
osmel briceno carrizo
3D generalist
freelance
caracas, Venezuela
 
Join Date: Sep 2012
Posts: 124
I did

Quote:
Originally Posted by gmask
you didn't declare $papa as a global variable


Yes, i did:

global string $papa[] = `ls -sl`;

But give me error:

// Error: Initialization of global variable "$papa" requires a constant value. //

I dont know why, and i dont know exactuly where to declare the global variable. I did it at the begining of the first global proc, but it shows that error.
 
Old 01-15-2013, 09:24 AM   #4
zoharl
A newbie
 
zoharl's Avatar
portfolio
Zohar
Wellington, New Zealand
 
Join Date: Mar 2009
Posts: 1,820
I didn't test it, but first declare it as global, then set it:

Code:
global string $papa[]; $papa = `ls -sl`;
 
Old 01-15-2013, 02:27 PM   #5
rgkovach123
Know-it-All
robert
austin, USA
 
Join Date: Nov 2006
Posts: 364
in general, I would avoid using global variables.

Instead of using Global Variables, write a function to return the father.

Code:
global proc string setFather () { string $papa[] = `ls -sl`; return $papa[0]; }


Code:
global proc setSons () { string $sons[] = `ls -sl`; string $papa = `setFather`; $myNum = (size(`ls -sl`)); for ($laps = 0; $laps <= $myNum; $laps++){ select -r $papa; select -add $sons; doCreateParentConstraintArgList 1 { "1","0","0","0","0","0","0","1","","1" }; } }
 
Old 01-15-2013, 02:31 PM   #6
gmask
Obfuscator
 
gmask's Avatar
gmask
Power Sitting
Topanga, USA
 
Join Date: Oct 2002
Posts: 6,937
Quote:
Originally Posted by meldu
Yes, i did

global string $papa[] = `ls -sl`;

But give me error:

// Error: Initialization of global variable "$papa" requires a constant value. //

I dont know why, and i dont know exactuly where to declare the global variable. I did it at the begining of the first global proc, but it shows that error.


you didn't mention that in your original post.
__________________
blah blah blah

Last edited by gmask : 01-15-2013 at 03:20 PM.
 
Old 01-15-2013, 02:44 PM   #7
meldu
PRO
portfolio
osmel briceno carrizo
3D generalist
freelance
caracas, Venezuela
 
Join Date: Sep 2012
Posts: 124
neither

Quote:
Originally Posted by zoharl
I didn't test it, but first declare it as global, then set it:

Code:
global string $papa[]; $papa = `ls -sl`;


i declare it two times, before the two procs:

//global proc that assing the father and sons
global string $papa[];

global proc setFather () {
//a variable that search and define who its the father
string $papa[] = `ls -sl`;
print $papa[0];
select $papa[0];

}


//global proc that for the sons
global string $papa[];
global proc setSons () {

string $sons[] = `ls -sl`;

$myNum = (size(`ls -sl`));

for ($laps = 0; $laps <= $myNum; $laps++){

select -r $papa[0];
select -add $sons
doCreateParentConstraintArgList 1 { "1","0","0","0","0","0","0","1","","1" };

}


}




//main window

window -rtf true -title "multiConstraint" multiCons;
columnLayout;

button -c "setFather" -label "father";

button -c "setSons" -label "sons";

showWindow multiCons;


Same error: // Error: "$papa" is an undeclared variable. //

Thanks.
 
Old 01-15-2013, 03:14 PM   #8
gmask
Obfuscator
 
gmask's Avatar
gmask
Power Sitting
Topanga, USA
 
Join Date: Oct 2002
Posts: 6,937
Quote:
Originally Posted by meldu
i declare it two times, before the two procs:


It needs to be inside the procs!!!


Code:
global proc setFather () { //a variable that search and define who its the father global string $papa[]; string $papa[] = `ls -sl`; print $papa[0]; select $papa[0]; }
__________________
blah blah blah
 
Old 01-15-2013, 03:19 PM   #9
zaskar
Expert
portfolio
franky****inFourFingaz
-
Dresden, Germany
 
Join Date: Dec 2010
Posts: 321
Its not enough to declare a variable somewhere. You need to make a procedure familiar with this variable, so declare $papa inside the procedure.

//ok obsolete
 
Old 01-15-2013, 05:32 PM   #10
zoharl
A newbie
 
zoharl's Avatar
portfolio
Zohar
Wellington, New Zealand
 
Join Date: Mar 2009
Posts: 1,820
Frankly, the doc explains it better than any of us:


http://download.autodesk.com/global...l_variables.htm
 
Old 01-15-2013, 05:49 PM   #11
meldu
PRO
portfolio
osmel briceno carrizo
3D generalist
freelance
caracas, Venezuela
 
Join Date: Sep 2012
Posts: 124
thanks

Quote:
Originally Posted by zoharl
Frankly, the doc explains it better than any of us:


http://download.autodesk.com/global...l_variables.htm



Thanks dude, i will keep trying
 
Old 01-15-2013, 06:35 PM   #12
rgkovach123
Know-it-All
robert
austin, USA
 
Join Date: Nov 2006
Posts: 364
i recommend avoiding global variables, they are usually not necessary and a bad habit to develop if you are just starting out scripting. See my post above for how to setup your procs to avoid the use of global vars.
 
Old 01-15-2013, 08:03 PM   #13
hominid
Expert
 
hominid's Avatar
portfolio
Pete Horvath
Calgary, Canada
 
Join Date: Sep 2002
Posts: 491
your forgot the ; on the line "select -add $sons"

Cheers,
Pete
 
Old 01-15-2013, 08:03 PM   #14
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 02:06 AM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.