Notifications
Clear all

[Closed] Making boxes in a line with random width problem

Hi everyone,

I have just started with maxscript and I’m trying to learn it. I’m trying to understand for loops and arrays and have got my self a little problem with probably a trivial solution. I hope there is someone that can help me with this!

My goal is to make one row of n connected boxes, all with varying width. Here is my script this far:

W = #()

for i=1 to 10 do
(

sumWidth=0; for val in W do (sumWidth += val)

width= (random 4 10)
pos=sumWidth


Box lengthsegs:1 widthsegs:1 heightsegs:1 length:5 width:width height:5 mapcoords:on pos:[0,0,0] isSelected:on
$.pivot = ($.center - [(width/2),0,0])

if i<2 then 
$.position = [0,0,0]
else
$.position = [pos,0,0]


W[i] = width

)
1 Reply
fn fn_boxRow = (
	delete objects
	local b
	local k = 0
	local rng
	local pos = [0,0,0]
	local obj = #()
	for i = 1 to 10 do
	(
		rng = (random 4 10)
		b = box()
		b.wirecolor = [random 0 255, random 0 255, random 0 255 ]
		b.length = 1
		b.height = 1
		b.width = rng
		append obj b
	)
	for i = 2 to (obj.count ) do (
		obj[i].pos.x = (obj[(i - 1)].max.x  + (obj[i].width /2.0))
	)
)
fn_boxRow()