Houdini: Using set() to make a vector


Using set() to make vectors


If you have ever used VEX you know that sometimes, if you are not an experienced coder, it can be frustrating to understand those syntax errors that seem to be in English but your morning coffee still seems clearer then what they are trying describe. 

One of the worst ones is "unexpected identifier". When you are setting a vector, this crops up every so often and when I was first using vex in a Wrangle Node or in my VEX Code this drove me crazy! Luckily, the solution around this error is simple.  

How to set a vector in Houdini:


Using set() you can 'set' the values for a vector or vector4. (see Houdini Documentation ) The syntax is really simple!

vector SomeVectorVariable = set( value1, value2, value3 );
vector4 SomeVector4Variable = set( value1, value2, value3, value4 );

Or for shorthand setting!

// p is the shorthand for Vector 
v@SomeVectorAttr = set( value1, value2, value3 );
p@SomeVector4Attr = set( value1, value2, value3, value4 );

I use set almost exclusively for setting vectors and when you start using complex matrices and arrays {} will just error whenever you need to evaluate a statement before setting it as the value for that index.