View Full Version : swap/alternate a value for each time used in for loop
pbarnes 11-12-2008, 07:44 PM so if i have a for loop with a duplicate command in it, and want the translate X value to swap from 1 to -1 for each dup run through
ie, it goes 1,-1,1,-1,1,-1 ect...
how?
cheers
|
|
Wick3dParticle
11-12-2008, 08:15 PM
Hey pbarnes.
Take a look at this loop...and apply it to your needs.
$a[$i] will spit back either 1 or -1 each time, depending on if $i is divisible by 2.
string $selection[] = `ls -sl`;
int $i = 0;
int $a[];
for ($each in $selection){
$i++;
if ($i % 2){
$a[$i] = 1;
}
else {
$a[$i] = -1;
}
print ($a[$i] + "\n");
}
Hope that helps,
~Ilan
pbarnes
11-13-2008, 02:00 PM
hey, well it does help but still not doin what i want
heres what i have
float $offsetY = $myYValue + 0.01;
float $offsetX = $myXValue / 2;
select -cl;
string $bricks[] = `ls "brick*"`;
//dup height
int $i = 0;
int $valueHeight = `intField -q -v myHeight`;
float $offBrickY = $myYValue + 0.02;
int $a[];
select $bricks;
for($i=0; $i<$valueHeight; $i++)
{
if ($i % 2){
$a[$i] = 0;
duplicate -rr; move -r 0 $offBrickY 0;
}
else{
$a[$i] = 1;
}
duplicate -rr; move -r $offsetX $offBrickY 0;
}
but it doesnt come back basicly i want it to go 0 then the variable of $offsetX the 0 ....ect
heres what it looks like with that code
Wick3dParticle
11-13-2008, 05:39 PM
if ($i % 2){
$a[$i] = 0;
duplicate -rr; move -r 0 $offBrickY 0;
}
else{
$a[$i] = 1;
}
duplicate -rr; move -r $offsetX $offBrickY 0;
}[/CODE]
but it doesnt come back basicly i want it to go 0 then the variable of $offsetX the 0 ....ect
heres what it looks like with that code
Ok...so you get a value of $a = 0 or 1...but what are you doing with $a?
It doesnt look like you are doing anything with that data.
for example:
if ($i % 2){
$a[$i] = 0;
}
else{
$a[$i] = 1;
}
duplicate -rr;
eval("move -r " + $offsetX + " " + $a[$i] + ";");
}
The code is just to demonstrate how to use the data from $a.
Hope that helps,
~Ilan
pbarnes
11-13-2008, 06:46 PM
soz but im still not getting it
int $i = 0;
int $valueHeight = `intField -q -v myHeight`;
float $offBrickY = $myYValue + 0.02;
int $a[];
select $bricks;
for($i=0; $i<$valueHeight; $i++)
{
if ($i % 2)
{
$a[$i] = 0;
}
else{
$a[$i] = $offsetX;
}
duplicate -rr; move -r $a[$i] $offBrickY 0;
}
but this just makes it go straight up and not alternate,
$a[$i] i have set to the variable of $offsetX which changes depening on the users setting the size of the brick
with the if else - do you only need one duplicate command,
i cant seem to get this to work
cheers
Wick3dParticle
11-13-2008, 07:32 PM
Why don't you post the full script you have there, and explain what exactly you are trying to achieve...and I will try my best to help you from there.
~Ilan
pbarnes
11-19-2008, 05:15 PM
thx for the help i have solved it now
i needed to make the values opposite of each other ie ones pos the other is neg otherwise wen u use 0 it doesnt move back to 0 it just stays in the same place causing the effect you see above
CGTalk Moderation
11-19-2008, 05:15 PM
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.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.