[Closed] loops
hi,
ive just begun learning maxscript and am trying to get what probably is quite a simple idea to work.
I want to copy a box lots of times (in the x direction) up to the “overall width” value. Each spacing is a random value between 0 and 1 but I would like it to be cumulative and it stops at the “overallwidth” value.
it may visually look a bit like this if it helps explain
i i i ii i i i i i ii i ii i i ii i i ii i iii i
however this script doesnt work properly & im not sure why? is it possible to do?
mattoso
global overallwidth = 50
global b = box length:0.1 width:0.1 height:3.2
(
spacing = b.pos.x
r = random 0.0 1.0
if spacing < (overallwidth – 1) then
(
[size=1]spacing = b.pos.x + r
copy b [spacing +r,0,0]
)
[/size]else
(
copy b [overallwidth,0,0]
)
)
Hi!
This will spread 1cm boxes between the specified distance:
-- create a box and set the first offset to 0
b = box pos:[0,0,0] width:1 height:1 length:1
offset = 0.0
-- continue copying the box until the specified distance is reached
while b.pos.x+1+offset < 50.0 do
(
-- Generate the offset
offset = random 0.0 1.0
-- copy the box into the same variable so it will remember it's new position
b = copy b
-- move the box to its new position
b.pos = [b.pos.x+1+offset,0,0]
)
-- move the last box to the specified distance
b.pos = [50.0,0,0]