VEXercise 4 – limit vertices

//loopp through verts and break up the shit
if(ch('../limitVerts') == 1) {
    int numVerts = primvertexcount(0, @primnum);
    if(numVerts > 2) {
        for(int i = 2; i<numVerts; i++) {
            //store vertex points
            int vtxNum1 = primvertices(0, @primnum)[i];
            int vtxPoint1 = vertexpoint(0, vtxNum1);       
            int vtxNum2 = primvertices(0, @primnum)[i-1];
            int vtxPoint2 = vertexpoint(0, vtxNum2);
            
            //create a new prim and add
            int newPrim = addprim(0, "polyline");
            addvertex(0, newPrim, vtxPoint1);
            addvertex(0, newPrim, vtxPoint2);
        }
        
        for(int i = 2; i<numVerts; i++) {
            //delete the old extra vertices in a separate loop
            int vtxNum = primvertices(0, @primnum)[i];
            removevertex(0, vtxNum);
       }
    }
}