Jump to content

acess previous point attribute in wrangle

Recommended Posts

Hi guys,

need help in vex. I tried creating an attribute in for loop and access the previous point value . But i couldn't access the created value. Here is the code. in this i am creating an integer a and storing the value. i am trying to use point(geoself) and access the previous point attribute but it defaults to zero. help me out with this.. thanks..


int @a=1;
int @test[];
int @inst;
for(int i=0;i<=@ptnum;i++)
@inst=point(geoself(),'a',i-1);   //cannot access the previous value



Share this post

Link to post
Share on other sites

You need to do such things in different wrangles, because geometry wrangles are writing attribute values at the very end of execution.

// First Point wrangle.
i@a = (@ptnum+1) * @ptnum / 2;

// Second Point wrangle.
i@a_prev = point(0, "a", @ptnum-1);


Or use Detail wrangle, use explicit functions for setting attributes and keep track of previous values manually:

// Detail wrangle.
int a = 0;
int a_prev = 0;

addpointattrib(0, "a", a);
addpointattrib(0, "a_prev", a_prev);

for (int i = 0; i < @numpt; i++)
    a_prev = a;
    a = (i+1) * i / 2;

    setpointattrib(0, "a", i, a);
    setpointattrib(0, "a_prev", i, a_prev);

The drawback of using Detail wrangle is that you need to use explicit functions, which is a bit more lines of code. It is also single-threaded, but still very fast in most cases.



Edited by f1480187
  • Like 1

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now