Notifications
Clear all
[Closed] defining objects within a loop
Feb 01, 2008 1:39 am
hi everyone, this is problay a really simple problem im having, but i cant seem to make a new pyramid object with the name incuding the loop varibal in it.
heres the code i’ve got so far
For index = 1 to 5 Do(
name_number = index as string
Pyr(index) = Pyramid widthsegs:1 depthSegs:1 heightsegs:1 width:25 depth:25 height:50 mapcoords:on transform:(matrix3 [1,0,0] [0,0,1] [0,-1,0] [3.11111,0,-1.77778])
Pyr(index).name = "Pyr " + name_number
)
(index) = 2
move Pyr(index) [10,10,10]
any help would be much appreached.
also if anyone can tell me how to rotate an object so-many degrees on the Z axis, would be much appreached.
cheers
3 Replies
Feb 01, 2008 1:39 am
ar=#() -- make empty array
For index = 1 to 5 Do
(
name_number = index as string
Pyr = Pyramid name:("Pyr"+name_number) widthsegs:1 depthSegs:1 heightsegs:1 width:25 depth:25 height:50 mapcoords:on transform:(matrix3 [1,0,0] [0,0,1] [0,-1,0] [3.11111,0,-1.77778]) -- you can assign name directly
append ar pyr -- add new pyramid stored in pyr variable to array
)
move ar[2] [10,10,10] -- move second array member
-- rotate, for example:
ar[3].rotation.z=90
this should work (i don’t have max here)
Feb 01, 2008 1:39 am
Can I assume you are trying to create an array of these objects as you create them?! Because that’s what it looks like and that’s not how to do it…
(
local lstPyr = #()
For index = 1 to 5 Do(
name_number = index as string
append lstPyr (Pyramid name:("Pyr " + name_number) widthsegs:1 depthSegs:1 heightsegs:1 width:25 depth:25 height:50 mapcoords:on transform:(matrix3 [1,0,0] [0,0,1] [0,-1,0] [3.11111,0,-1.77778]))
)
local index = 2
move lstPyr[index] [10,10,10]
)
Shane
Feb 01, 2008 1:39 am
cheers for that guys. i hadnt though to do it with an array, seems cleaner that my other approach tho.
mucho thanks