ScriptSpot

Forum topic · General Scripting

ForLoop parent to previous

By JokerMartini · 2011-03-07

Description

So I have a loop function that runs 4 times. Each time it runs it creates a box incrementally moving it along the x axis. How could I make the loop link to the box previously created in the loop?

Comments (1)

Answer!

JokerMartini · 2011-03-07


(
local parentBone = undefined
mybox = box length:10 width:10 height:10 wirecolor:blue --new box

for i = 0 to 5 do --repeat five times, for each iteration do:
(
box_copy = copy mybox --create a copy of the original box
box_copy.pos = [i*20, 0, 0] --place it i*20 units along x
if parentBone != undefined then
(
print "Link"
box_copy.parent = parentBone
)
parentBone = box_copy
)--end of the for loop
)