Maxscript, can any one explain this script to me (be very clear)

107 views Asked by At

--Lego brick wall
shift = true
for z in 0 to 9 do
(
shift = not shift; -- why colon?
for x = 0 to 9 do (copy $Lego).pos = if shift then [40*x,0,20*z] else[20+ 40*x,0,20*z]
)

1

There are 1 answers

0
Swordslayer On

Line by line, first you set a variable which controls whether you are shifting the row or not. Then for row index z from zero to ten you switch the shift from true to false and vice versa. The semicolon is optional and not really needed. That's the outer loop. In the inner for loop, for each column index x from zero to nine you create a copy of a scene node named Lego - this returns a the object itself, so you can directly set its position given by the mulitples of indices - and add a shift in x axis if the row number is even.

You can also use modulo check if the row index is even and instead of creating a copy of the object and setting its position afterwards do it in the constructor:

for z in 0 to 9 do
(
    local shift = if mod z 2 == 0 then 20 else 0
    for x = 0 to 9 do copy $Lego pos:[shift + 40 * x, 0, 20 * z]
)