Jump to content
ciel9979

VEX supports array function?

Recommended Posts

Hi, this is my first post here. :)

I've been trying to call a vector array function in VEX, but it either returned "Internal Compiler Error" or "Syntax error, unexpected identifier, expecting ';'". I also checked Array help file and the example as below didn't work at all:

 

To specify a literal array, use curly braces, with the array members separated by commas:
vector[] rgb_array()
{
return { {1, , }, {, 1, }, {, , 1} };
}

 

Here is the simple code I tried to compile, but it returned an error message "Syntax error, unexpected identifier, expecting ';'." :(

 

vector an_array[] = {{1,1,1}, {2,2,2}};
vector a[];

vector[] testFunction(vector[] a){
    return a;
}

a=testFunction[an_array];

 

 

Does anyone know if VEX supports array function? Thank you very much!

Share this post


Link to post
Share on other sites

I think you can only return arrays in specific places like Outer Code fields of Inline/Snippet VOP and standalone VEX operators like VEX SOP, etc. Just define the functions in those places and then call them in the Code field.

  • Like 2

Share this post


Link to post
Share on other sites

Thanks for your reply, magneto. My codes are in snippet vop inside the attribVOP. For those non-array functions like "vector testFunction(vector a)", they work, but not for "vector[] testFunction(vector[] a)" -_-

Maybe it's VEX that hasn't supported array functions yet :(

Share this post


Link to post
Share on other sites

Yeah just paste those functions into Outer Field. You can't do this using Wrangle SOPs as the Outer Field parameter is not exposed. So you have to use AttribVOP SOP with a Snippet/Inline VOP.

Share this post


Link to post
Share on other sites

Hi,

If you use a vfl include file to store your function, you can return an array. And then you can use that signature  "vector[] testFunction(vector[] a)"

:)

Share this post


Link to post
Share on other sites

This was a very old topic :P (possibly talking H13 here) I am pretty sure more array support was added in native H14 and onwards.

Share this post


Link to post
Share on other sites

Wrangles (more generally, functions defined inside other functions), still not support returning arrays in Houdini 15.5. Most convenient workaround is modifying an argument.

In code file:

float[] foo()
{
    return array(1, 2, 3, 4, 5);
}

bar = foo();

In wrangle:

void foo(float arr[])
{
    arr = array(1, 2, 3, 4, 5);
}

foo(bar);

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Year 2019...had issue with this in Houdini 17.5.

Solution is to add word 'function' and everything works only then.
function int[] getPointsForPrim(int targetPrimID){
    int pts[] = primpoints(0, targetPrimID);
    return pts;
}

  • Thanks 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×