fabsberry Posted January 21, 2018 Share Posted January 21, 2018 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"? Quote Link to comment Share on other sites More sharing options...
Atom Posted January 21, 2018 Share Posted January 21, 2018 Check out this post on the topic. Basically the variables can't be written to because all new point values are read from the first time input. Your setpointattrib won't actually run until the VEX node exits the code and updates it's initial input with the final value. Quote Link to comment Share on other sites More sharing options...
f1480187 Posted January 21, 2018 Share Posted January 21, 2018 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); 1 Quote Link to comment Share on other sites More sharing options...
fabsberry Posted January 21, 2018 Author Share Posted January 21, 2018 (edited) Thank you, it makes more sense now! Edited January 21, 2018 by fabsberry Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.