VEX : using FOR wihtout errors but doesn't work

   2199   4   0
User Avatar
Member
1075 posts
Joined: 4月 2017
Offline
Hi!

I've got 2 curves merged together for a total therefore 2 primitives. I'm trying to make a detail array attribute storing all the positions of all the curves (I'll be adding more curves later). I'm getting no errors but the detail array is still empty…

I'm stuck!

int stop = @numprim;

for(int i=0; i == stop; i++)
    {
    vector pos = prim(0, "P", i);
    push(f[]@zpos, pos.z);
    }

Thanks for any help!

-Olivier

Attachments:
for_no_errors_wont_work.JPG (78.5 KB)

User Avatar
Member
23 posts
Joined: 3月 2013
Offline
You're very close! Your condition in the for loop is currently i==stop, meaning the loop will run as long as i==stop returns true. When the loop starts, i=0 which is not equal to stop (in your example stop would be equal to 2 and in all cases would be greater than 0). I guess it technically isn't incorrect code is why it doesn't error out but it doesn't run as expected.

If you change your for condition to:

for(int i=0; i<stop; i++)


it will work as expected.


Full code only changing that one line:

int stop = @numprim;

for(int i=0; i<stop; i++)
    {
    vector pos = prim(0, "P", i);
    push(f[]@zpos, pos.z);
    }
Edited by davidderwin - 2018年10月22日 15:11:52
User Avatar
Member
1075 posts
Joined: 4月 2017
Offline
Thanks!

I kept thinking of a “stop” condition rather than a “continue while” condition…

The other thing not working was my line:

int stop = @numprim;

…It's in a detail wrangle so it did not find the @numprim. I also tried using:

int stop = prim(0, "numprim", 0);

…but that gave me “0” instead of “2”. I still don't get that problem. So I ended up creating a primitive wrangle just before and using the setdetailattrib so my numprim would be in the detail attributes. From there, I was able to use that value.

So much troubleshooting for so little effect. Thanks for the help!

-Olivier
User Avatar
Member
8785 posts
Joined: 7月 2007
Offline
olivierth
…It's in a detail wrangle so it did not find the @numprim.
@numprim is perfectly valid in Detail wrangle, should return number of primitives of the first input geometry
alternatively you can do nprimitives(0)
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
1075 posts
Joined: 4月 2017
Offline
hmmmm…


It wasn't working when I tried @numprim. There must be another explanation.

Thanks for the info!

-Olivier
  • Quick Links