[Closed] Array values overwriting each other?
Hi,
I got the following code:
stammArr = for i in 1 to TabRols.stammRollout.stammAnzahl.value collect (-- Erstelle so viele Stämme wie im Spinner angegeben sind.
stamm = cylinder radius:3 height:100 sides:8 height:((TabRols.heckeRollout.heckenHoehe.value/100)*75) wirecolor:brown name:("stamm_"+(i as string))
stamm.position.controller = path_constraint()
stamm.position.controller.path=TabRols.heckeRollout.heckenpfad.object
deleteKeys stamm.position.percent.controller #allKeys
stamm.position.controller.percent = (((i-1) as float)/(TabRols.stammRollout.stammAnzahl.value-1))*100
)
And then I want to create boxes at the position of each cylinder via the following:
for i in 1 to stammArr.count do ( -- Erstelle so viele Volumenboxen Stämme vorhanden sind.
box pos:stammArr[i].pos
)
And i get the following error:
MAXScript Rollout Handler Exception: – Unknown property: “pos” in 0.0 <<
When I print out the array i get something like 0.0, 25.0, 50.0, 75.0 etc.
I think its like the values of the array only containt the last information I supplied in the collect loop; the path percent.
How can I solve this? AM I doing some fundamental stuff wrong here?
– EDIT –
If i do:
for i in stammArr do ( -- Erstelle so viele Volumenboxen Stämme vorhanden sind.
box pos:stammArr[i].pos
)
I get the error:
>> MAXScript Rollout Handler Exception: – Runtime error: array index must be positive number, got: 0.0 <<
it’s pretty simple, you are collecting the percentage value into the stammArr array, not the cylinder object.
The value at the last line between the brackets following the collect keyword is the value that is collected into the array. In your case the float value of the percentage property. All you have to do is put the stamm variable at the end of the code block like this:
stammArr = for i in 1 to TabRols.stammRollout.stammAnzahl.value collect (-- Erstelle so viele Stämme wie im Spinner angegeben sind.
stamm = cylinder radius:3 height:100 sides:8 height:((TabRols.heckeRollout.heckenHoehe.value/100)*75) wirecolor:brown name:("stamm_"+(i as string))
stamm.position.controller = path_constraint()
stamm.position.controller.path=TabRols.heckeRollou t.heckenpfad.object
deleteKeys stamm.position.percent.controller #allKeys
stamm.position.controller.percent = (((i-1) as float)/(TabRols.stammRollout.stammAnzahl.value-1))*100
[b]stamm[/b]
)
Ok thanks, but how can I access the lets say path position percentage of a specific item in this array later on?
– EDIT –
Ah forget it, now I see thanks dude!