View Full Version : Help with for loop!!!
Stucky 12082005, 02:00 PM Hi guys. I have a problem. I want to do a for loop, that detects the objects that are selected and put each one aligned in the Z axis in the grid, and each one will be 10units apart from the next one. I've managed to do part of that. I cant find a way to check what was the position in Z of the previous object in the loop, and add 10 to that value. I hope you could help this time. This is what I have so far:
string $sel[] = `ls sl`;
for ($i = 0; $i < size($sel); $i++)
{
xform a translation 0 0 ($i+=1) ($sel[$i]);
}
I know I can't have that Z = ($i+=1) cause it will jump in the objects that are selected, and not going through everyone of them. I cant find a why to increment 10units in Z, everytime a loop runs...Thanks in advance for your suport.
S


Bonedaddy
12082005, 02:41 PM
xform a translation 0 0 ($i*10) ($sel[$i]);
Stucky
12082005, 02:47 PM
Hey bonedaddy, one more time, you saved my life, hehe...Thats exactly what I want. Thanks dude.
Now I have another question. Imagine I have hundreds of cubes. I dont want that the last cube will go to, say, 10000000 units in Z. Is there a way to tell it, that everytime Z = 100, it jumps 10 units in X, and starts again from Z = 0? thanks in advance dude..
probably I would have to use a switch.
S
goleafsgo
12082005, 03:11 PM
(($i*10)%100)
Stucky
12082005, 03:23 PM
goleafsgo  Dude thanks for the reply, but I dont understand what that does. I think you missed my point. I want that every time that Z = 100, X will increment 10, and Z start from 0 again.
S
goleafsgo
12082005, 03:56 PM
% is the mod operator. What it does is divides two numbers and returns the remainder.
So if ($i*10) is equal to 100 then (($i*10)%100) would equal 0.
Try running this code...
{
int $i;
for ($i=0; $i<100; $i++)
{
int $z = (($i*10)%100);
print ("z is " + $z + "\n");
}
}
...and it will print out this...
...
z is 0
z is 10
z is 20
z is 30
z is 40
z is 50
z is 60
z is 70
z is 80
z is 90
z is 0
z is 10
z is 20
z is 30
z is 40
z is 50
z is 60
z is 70
z is 80
z is 90
z is 0
z is 10
z is 20
z is 30
z is 40
z is 50
z is 60
z is 70
z is 80
z is 90
...
Is that what you wanted?
Stucky
12082005, 05:17 PM
Thanks dude. I will try that right away. After I test it, I'll say something..
S
Stucky
12082005, 05:43 PM
ok dude. This works great. Thanks. Now I wanna say that every time Z = 0, x will increment 10 units. I will try to find a way to do that, but do you know how to do that? thanks...
S
Vormav
12082005, 06:10 PM
ok dude. This works great. Thanks. Now I wanna say that every time Z = 0, x will increment 10 units. I will try to find a way to do that, but do you know how to do that? thanks...
S
Just add something like this within your loop:
int $z = (($i*10)%100);
if($z == 0) {
$x += 10;
}
Stucky
12082005, 07:48 PM
vormav, thats what i've been trying. But its not that simple. Thanks dude.
S
CGTalk Moderation
12082005, 07:48 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 ©20002014, Jelsoft Enterprises Ltd.