Houdini Resources

Updated on June 26  2024


WrangleSnippetQuickReference

Deborah R. Fowler



Wrangle Node Syntax Quick Reference for Beginners

Posted Oct 17  2018
Updated Nov 6  2020

A really excellent "cheat sheet" by John Kunz https://mrkunz.com/blog/08_22_2018_VEX_Wrangle_Cheat_Sheet.html

For those of you who are less familiar with C-like syntax or are switching back and worth between languages this quick guide to common syntax may be helpful.



Variables
  • are typed in vex  ie.) int, float, string
  • Newly declared variables have undefined value - INITIALIZE before use
  • should be named meaningfully (coding standards) ie. hps is not good, hitsPerSecond is good -
  • name can't be a keyword or start with a number

Random Numbers

float randomNumber = rand(@ptnum);

OR

float randomNumber = random(@ptnum);

Notation

Popular Shorthand
Common Symbols
    x = x + 1;   
    x += 1;    
    x++;       
    ++x;  
 

// All of these increment x by one
  • ++ prefix increments and then uses
  • ++ postfix uses and then increments

!=

==
<=
>=
<
>
%
Blocks
  • defined with curly braces
  • make it visually easy to see these (on their own line - coding standard)
         {
        
}
If/then/else

if ( condition )
{
    statements;
}
else
{
    statements;
}
Looping
  • while
  • for
  • do while
while( condition )
{
        // do something
}
for ( int i = 0; i < something; ++i )
{
        // do something
}
do
{
        // do something
} while ( condition);
Functions

int myFunction()
{
        statements;
        return 0;  // return some value
}

(must be defined before used)
Procedures (functions that act on data but don't explicitly return a value) - now mostly lumped under the word functions

void myFunction()
{
        statements;
}
Parameters/Arguments

int myFunction( int x, float y )
{
        int resultVariable;
        // x and y are parameters and are local to the function
        // they take on the value of the argument
        return resultVariable;
}

To call a function (or procedure) you call its name, for example to run this piece of code

int resultFromCalling = myfunction( 10, 12.6 )

Arrays
int myArray[];

remember counting starts at 0

myArray[0] = 5;

Attributes

@

fetch or creates attributes

in vex snippets attributes can be created and are type specific
For example i@myVar, v@myArray etc.

 
@ptnum
@numpt
@P
@Cd
@P.x
@Cd.r

int @kermit or i@kermit creates an attribute
List of hard to guess functions:

rint - rounds a number to an integer value (similar to hscript round)
MISSING

getbbox_size, getbbox_max, (omin, center), also using "op:path" - equivalent to hscript bbox function
MISSING

sprintf - used for texture override for example

MISSING