undeclared variable

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 01 January 2013   #1
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 January 2013   #2
you didn't declare $papa as a global variable
__________________
blah blah blah
 
Old 01 January 2013   #3
I did

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 January 2013   #4
I didn't test it, but first declare it as global, then set it:

global string $papa[];
$papa = `ls -sl`;
 
 
Old 01 January 2013   #5
in general, I would avoid using global variables.

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

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


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 January 2013   #6
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 January 2013 at 03:20 PM.
 
Old 01 January 2013   #7
neither

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

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 January 2013   #8
Originally Posted by meldu: i declare it two times, before the two procs:


It needs to be inside the procs!!!


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 January 2013   #9
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 January 2013   #10
Frankly, the doc explains it better than any of us:


http://download.autodesk.com/global...l_variables.htm
 
Old 01 January 2013   #11
thanks

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 January 2013   #12
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 January 2013   #13
your forgot the ; on the line "select -add $sons"

Cheers,
Pete
 
Old 01 January 2013   #14
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



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 06:24 PM.


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