Vex Foreach Loop issue

   6319   3   1
User Avatar
Member
32 posts
Joined: Jan. 2017
Offline
Anyone know why my i value isn't iterating by 1 each time? I made arrays of primitives by their group. I want to set a “primlevel” attribute for each primitive in an array / group that corresponds with its index value in the array, but it assigns each index in the array a value of 1 instead of incrementing.

//Arrays by Group
int leftstraights=array(@group_leftstraights);;
int rearcurves=array(@group_rearcurves);
int rightstraights=array(@group_rightstraights);
int frontcurves=array(@group_frontcurves);

foreach(int i; leftstraights){
int addattrib= setprimattrib(0, “primlevel”, @primnum, i, “set”);
}
User Avatar
Staff
4199 posts
Joined: Sept. 2007
Offline
It won't work because i@group_leftstraightswill always be an integer. The wrangle snippet is being run on each primitive, so that group/attr represents whether the current element is part of that group or not. You can see this if you save that array to an attribute (see the image attachment).

Also, to get an integer array variable, the syntax is this (brackets after the variable):

int foobar[] = array(1,3,5,2,8,9,2,5);

Or maybe I've misunderstood what you're trying to achieve?

Attachments:
screenshot-area-2017-06-28-224128.png (36.3 KB)

I'm o.d.d.
User Avatar
Member
32 posts
Joined: Jan. 2017
Offline
goldleaf
It won't work because i@group_leftstraightswill always be an integer. The wrangle snippet is being run on each primitive, so that group/attr represents whether the current element is part of that group or not. You can see this if you save that array to an attribute (see the image attachment).

Also, to get an integer array variable, the syntax is this (brackets after the variable):

int foobar[] = array(1,3,5,2,8,9,2,5);

Or maybe I've misunderstood what you're trying to achieve?

thanks, but the original code does have the brackets (I think the forum edited them out and the group settings work. It's just the int i in the foreach loop that's not incrementing in value setting the attribute to 1 across the board in the array vs. 1, 2, 3, etc.
User Avatar
Member
133 posts
Joined: July 2005
Offline
You are iterating across all primitives and then in a foreach loop over all primitives in a group each time. So for each primitive you are setting it to 1 exactly N times of the length of the group array. I would think thats not what you are trying to do . Rethink logic, or do everything in a detail wrangle to run only once.
  • Quick Links