Default values for function arguments in vex snippets error

   3489   5   1
User Avatar
Member
12 posts
Joined: March 2017
Offline
The snippet
int test(int a;int b=2)
{
return a+b;
}

returns invalid default value for parameter b error

Is there a way to have default values for function arguments in vex snippets?
User Avatar
Member
2042 posts
Joined: Sept. 2015
Offline
int test(int a,b)
{
int Result;
c = 2;

if //code on this line for condition that is met to use default
{
Result = a + c;
}
else
{
Result = a + b;
}

return Result;
}
Edited by BabaJ - Oct. 30, 2017 10:14:41
User Avatar
Member
8598 posts
Joined: July 2007
Offline
if you expect it to work like python and being able to just omit b to get the defaults, then it's not automatic
you can however create the representation of the function with just a and use default value for b inside
like this:

int test(int a;int b)
{
    return a+b;
} 
int test(int a)
{
    int b = 2;
    return test(a, b);
} 

printf("%g\n", test(1)); // returns 3 (1 + default 2)
printf("%g\n", test(1,1)); // returns 2 (1 + 1)
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
2 posts
Joined: March 2017
Offline
tamte
if you expect it to work like python and being able to just omit b to get the defaults, then it's not automatic
you can however create the representation of the function with just a and use default value for b inside
like this:

int test(int a;int b)
{
    return a+b;
} 
int test(int a)
{
    int b = 2;
    return test(a, b);
} 

printf("%g\n", test(1)); // returns 3 (1 + default 2)
printf("%g\n", test(1,1)); // returns 2 (1 + 1)

That's exactly what i did)
Still it's strange that this example errors out in snippets

taken from http://www.sidefx.com/docs/houdini/vex/lang [www.sidefx.com]
surface
noise_surf(vector clr = {1,1,1}; float frequency = 1;
           export vector nml = {0,0,0})
{
    Cf = clr * (float(noise(frequency * P)) + 0.5) * diffuse(normalize(N));
    nml = normalize(N)*0.5 + 0.5;
}
User Avatar
Member
8598 posts
Joined: July 2007
Offline
lizardstailz
Still it's strange that this example errors out in snippets
I don't think you can define a shader in the snippet
snippet already runs within the context function

so you can use just normal VEX functions, which don't have default values for arguments
Edited by tamte - Oct. 30, 2017 17:25:16
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
12 posts
Joined: March 2017
Offline
Ok, thanks for the answer)
  • Quick Links