[Closed] assistance with for loop having an undefined value
I am a novice in maxscript and if I could have a little help I would appreciate it. I wrote the below, and when I run the code it’s part of I get “undefined” on the print temparray[1] section… however if I put print i.material or print j I do get correct values, I also assume that the “(i.material) == j then” section must be working as if not it would
not be printing “undefined”…
I don’t know if it is… well I have ideas but I really don’t know what to do yet… does anyone know what I am doing wrong? I really appreciate any assistance given. Thank you.
selArray = getcurrentselection()
for m in selArray do (
if classof (m.material) == Arch___Design__mi then
appendIfUnique selectionMatArray (m.material)
)
for i in selArray do (
for j in selectionMatArray do(
for i in selArray do(
if classof(i.material) == j then
append temparray i --("1")
print temparray[1]
)
appendIfUnique masterArray temparray
)
)
I am guessing it may be because you are using the same loop nested within itself. You should always use unique variables for loops to prevent this. I would remove the interior i loop as it is redundant and may be the cause of your issue. I am also guessing this a code portion of a large script. If you don’t post the full thing it can be hard to diagnose.
-Eric
I since re-wrote the code and it now works. Thank you very everyone’s time.