Odd Bug In maxscript

Submitted by rootmaster on Tue, 06/12/2018 - 00:11

(    
    --在append tempPos时候并没有分配新的内存给array里的新成员,而是给的reference
    tempAreaBoundPntArr = #();
    tempPos0 = tempPos1 = tempPos2 = tempPos3 = [0,0,0];
    temp_x = 20;
    temp_y = 10;
    
    tempPos0.x = temp_x;
    tempPos0.y = temp_y;
    append tempAreaBoundPntArr tempPos0;
    format "tempPos:%\n" tempPos0;
    tempPos1.x = temp_x;
    tempPos1.y = -temp_y;
    append tempAreaBoundPntArr tempPos1;
    format "tempPos:%\n" tempPos1;
    tempPos2.x = -temp_x;
    tempPos2.y = -temp_y;
    append tempAreaBoundPntArr tempPos2;
    format "tempPos:%\n" tempPos2;
    tempPos3.x = -temp_x;
    tempPos3.y = temp_y;
    append tempAreaBoundPntArr tempPos3;
    format "tempPos:%\n" tempPos3;
    format"tempAreaBoundPntArr:%\n" tempAreaBoundPntArr;
)

-----------------------------------------------------
--pos 总是传递的refer
a=[0,0,0]
b= [1,1,1]
a  = b -- a and b refer the same data [1,1,1] stored in the same place
b.x += 1
2.0
a
[2,1,1]
--force to malloc new memory for a
--also can use a.x = b.x;a.y = b.y;a.z = b.z;
a = b - [0,0,0]--a and b do not refer the same value stored in differen place
[2,1,1]
a
[2,1,1]
b
[2,1,1]
b.x += 1
3.0
a
[2,1,1]
b
[3,1,1]

----------------------------------------------------------------------

tempPos = polyop.getvert GridData testPntIndex;
clearArr OcdVerts;
format "tempPos:%\n" tempPos;
format "tempAreaBoundPntArr:%\n" tempAreaBoundPntArr;
for i = 1 to tempAreaBoundPntArr.count do
(
    tempTestAreaBoundPntArr[i] = tempAreaBoundPntArr[i] + tempPos;
)
format "tempAreaBoundPntArrAft:%\n" tempAreaBoundPntArr;
--output
-- tempPos:[487.139,48.9204,0]
-- tempAreaBoundPntArr:#([22.3297,29.7729,0], [22.3297,-29.7729,0], [-22.3297,-29.7729,0], [-22.3297,29.7729,0])
-- tempAreaBoundPntArrAft:#([22.3297,29.7729,0], [22.3297,-29.7729,0], [-22.3297,-29.7729,0], [-22.3297,29.7729,0])

---------------------------------------------------------

want a unique element array ?

arry = #(5,5,7,8,9,3,3,3,3);

for i=1 to arry.count do
(
    num = arry[i];
    print arry[i];

    for j = i+1 to arry.count do
    (
        if j <= arry.count and num == arry[j] then
        (
            deleteItem arry j;
        )
    )
)

print arry