A Simple Vex issue

   1711   2   0
User Avatar
Member
4 posts
Joined: Aug. 2014
Offline
Hi, I am trying to get the point numbers in an array from a line.
And my code is;

int myPointsID;
int myPoints;
//resize(myPoints, 1);

for(int i = 0; i < npoints(0); i++)
{
myPointsID = point(0, “id”, i);
append(myPoints, myPointsID);
}
printf(“%d\n”, myPoints);


The result {0,0,0,0,0,0,}…. What is my mistake?
User Avatar
Member
2534 posts
Joined: June 2008
Offline
Check out the help [www.sidefx.com].
The value of the given attribute on the given point number, or 0 if the attribute or point do not exist.
Your attribute id must not exist, so it returns zero.

Returning zero, for a function that fails, is really a bad idea by SideFX. What if the actual value is zero?
Edited by Enivob - Sept. 25, 2019 08:58:16
Using Houdini Indie 20.0
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
User Avatar
Member
2038 posts
Joined: Sept. 2015
Offline
Returning zero, for a function that fails, is really a bad idea by SideFX. What if the actual value is zero?

Some value will have to be returned, and whatever that value is there is always the chance that the attribute value is the same e.g. -1 or 1 on fail.

It's not that it's a bad idea for 0 to returned, it's just necessary to know what the value might be of a given function for a fail and set up your attributes/code beforehand to handle the potential situation and make the distinction.

Also considering that most attributes that are created and unless specified, are assigned a default value of 0.

So this is another reason to consider what/how your attribute values will be assigned before using them.

One could also use one of the function variations of hasattrib() before using other functions or not, to help clarify the results.
  • Quick Links