Jump to content

VEX: for i


fabsberry

Recommended Posts

Hello, I have a problem understanding "for i" in vex.
 

for (int i=0; i<npoints(0); i++) {

    float val = point(0, "value", i);
    float preval = point(0, "value", i-1);
    
    float calc = val+preval;
    
    setpointattrib(0, "value", i, calc, "set");
}

 

In the picture you can at first see my initial values.
Now i want to add the sum of the previous values to my current value . 
 
I wrote the values i expected to get in red. 
 
What is wrong with my "for i"? 

values.jpg

Link to comment
Share on other sites

You need to do it in different way, like this:

float accum = 0;

for (int i = 0; i < @numpt; i++)
{
    float val = point(0, "value", i);
    accum += val;
    setpointattrib(0, "value", i, accum);
}

Input doesn't changed during the code execution, we can't change and retrieve changed attribute values within same wrangle using geometry functions. If you set input point #1 @value from 1.0 to 2.0, when you query input point #1 value again using point() function, you still get unchanged value of 1.0. If you operate on points/vertices/primitives, you can use @-bindings, they are ordinary variables internally, and will work.

// Point Wrangle.

// Works.
@foo = 5.0;
@foo = @foo * 2.0;

// Doesn't work.
setpointattrib(0, "bar", @ptnum, 5.0);
setpointattrib(0, "bar", @ptnum, float(point(0, "bar", @ptnum)) * 2.0);

 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...