Deborah R. Fowler
Wrangle Node Syntax Quick Reference for Beginners
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 forth between languages, this quick guide to common syntax may be helpful.
Variables
- Are typed in VEX — e.g.
int,float,string - Newly declared variables have undefined value — INITIALIZE before use
- Should be named meaningfully (coding standards) — e.g.
hpsis not good,hitsPerSecondis 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
x = x + 1;
x += 1;
x++;
++x;
// All increment x by one
++ prefix increments then uses
++ postfix uses then increments
x = x + 1;
x += 1;
x++;
++x;
// All increment x by one
++ prefix increments then uses
++ postfix uses 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
}
{
// do something
}
for ( int i = 0; i < something; ++i )
{
// do something
}
{
// do something
}
do
{
// do something
} while ( condition );
{
// 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,
// local to the function;
// they take on the value
// of the argument
return resultVariable;
}
To call a function, use its name:
int result = myFunction( 10, 12.6 );
Arrays
int myArray[]; // remember counting starts at 0 myArray[0] = 5;
Attributes
The @ symbol fetches or creates attributes. In VEX snippets, attributes can be created and are type-specific:
i@myVar v@myArray
Common built-in attributes:
@ptnum @numpt @P @Cd @P.x @Cd.r int @kermit // or i@kermit // creates an attribute
Example Files
Example File
random.hipnc
Example File
shorthandVex.hipnc
Example File
commonsymbols.hipnc
Example File
fetch.hipnc
Example File
rint.hipnc
Example File
bboxInVex.hipnc
Example File
RBDVarySizeNTexture.hipnc