Jump to content

accessing element of array attribute


j00ey

Recommended Posts

I'm trying to access specific elements of an array. I know I can do it like this :

float heights[] = detail(geoself(), 'row0', 0);
v@P.y = heights[i@col];

but I'm sure sometime before I was able to do it something like this :

v@P.y= detail(geoself(), 'row0', 0)[i@col];


Am I imagining it or can someone tell me the correct syntax? Thanks very much

Link to comment
Share on other sites

@P.y= float[](detail(0, 'row0'))[1]; 

You need to manually specify output type for detail function signature you need, because many of them exist. VCC usually tell you that you are using ambiguous function signature. But not always. For example, first line of this code is fine for compiler, but will silently break your code with a bug which may be hard to find.

@P = point(0, "P", @ptnum) * 2;         // Does unexpected stuff.
@P = vector(point(0, "P", @ptnum)) * 2; // Scales object twice.

Compiler is not so clever. It tries to guess which one of 18 possible return types of point(int; string; int) function you need:

float point( int; string; int )
float[] point( int; string; int )
int point( int; string; int )
int[] point( int; string; int )
matrix point( int; string; int )
matrix2 point( int; string; int )
matrix2[] point( int; string; int )
matrix3 point( int; string; int )
matrix3[] point( int; string; int )
matrix[] point( int; string; int )
string point( int; string; int )
string[] point( int; string; int )
vector point( int; string; int )
vector2 point( int; string; int )
vector2[] point( int; string; int )
vector4 point( int; string; int )
vector4[] point( int; string; int )
vector[] point( int; string; int )

Then it sees that it's multiplied by integer (because there is 2 instead 2.0) and chooses to use integer-returning signature. In result, @P.x value will be fetched by this function, rounded to nearest integer, then multiplied by 2, then converted to float and assigned to all three components of @P. In second case, vector-returning signature will be used. Then 2 will be converted converted to 2.0 and vector components will be multiplied with it.

  • Like 2
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...