VEX Tips & Tricks: If -statements, Ternaries, and Group Syntax

Well, I’m now a proud holder of a BFA in visual effects. My post graduation plan was to travel a bit and then get a job, but that isn’t happening, which leaves plenty of time for existing in Houdini-land. VEX is a C-based language, so most of these won’t be a surprise if you’re used to working with C-based languages.

Onto the fun stuff!

One Line If Statements

Instead of doing:

if(@P.y>0)
{
@P.z=0;
}

You can condense it into a one line if statement. This only works if you have one line of code inside the curly brackets:

if(@P.y>0)  @P.z=0;

Ternary Operator

(aka one line if-else statements)

Instead of doing:

if(@P.y>0)
{
@N.y=1;
}
else
{
@N.y=-1;
}

You can do:

@N.y = (@P.y>0) ? 1 : -1;
/* format being:
valueToSet = (condition) ? valueIfTrue : valueIfFalse;
*/

@group_groupname syntax

Instead of using setpointgroup() and inpointgroup(), you can use the @group_groupname syntax. This way, you can modify groups in the same way you can modify attributes.

//instead of:
if(inpointgroup(0,"up",@ptnum)==1)
{
setpointgroup(0,"alsoUp",@ptnum,1,"set");
}
//you can do:
if(@group_up==1)
{
@group_alsoUp=1;
}

Bonus: every single attribute and variable that means something to Houdini.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jessica Beckenbach

Jessica Beckenbach

41 Followers

Houdini / Technical Artist. SCAD Visual Effects ‘20. Lives and breathes Houdini, Nuke, Unreal, and (sometimes) Maya.