j00ey Posted January 4, 2017 Share Posted January 4, 2017 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 Quote Link to comment Share on other sites More sharing options...
f1480187 Posted January 4, 2017 Share Posted January 4, 2017 @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. 2 Quote Link to comment Share on other sites More sharing options...
j00ey Posted January 4, 2017 Author Share Posted January 4, 2017 I see, that makes sense - and it works too! Thanks very much for the explanation.. 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.