PDA

View Full Version : defining objects within a loop


jifman
02-01-2008, 12: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

vize
02-01-2008, 12:55 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)

RustyKnight
02-01-2008, 12:56 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

jifman
02-01-2008, 04:42 PM
cheers for that guys. i hadnt though to do it with an array, seems cleaner that my other approach tho.

mucho thanks

CGTalk Moderation
02-01-2008, 04:42 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.