Loops and Conditionals  (Animation Script)

Loops are used to repeat a series of animation instructions
Conditionals are used for flow control of animation instructions

Comparison Operators

 < Less than
 <= Less than or equal
 > Greater than
 >= Greater than or equal
 != Not equal
 = Equal

Note: When '=' operator is used in a conditional it compares for equal and does not assign.


Loop/Conditional Code block

All code that is part of loop or conditional is enclosed by { }
{ must be on next line immediately after loop/conditional statement
} Must close loop/conditional block

Parameter Modifiers
( - ) Use negative value for loop/conditional parameter

Notations
VERTEX - Declared VERTEX variable / object center from named Object variable
SurfacePlane - Surface plane from named Surface variable
float - Scalar floating point constant or VERTEX variable component (.x/.y/.z)
Cmp Op - Comparison operator listed above

Conditionals Description and parameter type variations
if
else
else if
Compare one value to another and conditionally branch

Compare scalar floating point values
if(float x Cmp Op float y)
{
   Code when compare condition succeeds
}

Compare VERTEX to Plane represented by named Surface variable
if(VERTEX V  Cmp Op SurfacePlane)
{
   Code when compare condition succeeds
}
VERTEX < SurfacePlane compares if VERTEX is in back of SurfacePlane
VERTEX > SurfacePlane compares if VERTEX is in front of SurfacePlane

Compare VERTEX to Plane represented by named Surface variable with offset distance
if(VERTEX V  Cmp Op SurfacePlane, float OffsetDistance)
{
   Code when compare condition succeeds
}
VERTEX < SurfacePlane compares if VERTEX is in back of SurfacePlane by offset distance
VERTEX > SurfacePlane compares if VERTEX is in front of SurfacePlane by offset distance

else condition may follow an if block
if(float x Cmp Op float y)
{
   Code when compare condition succeeds
}
else
{
   Code when compare condition fails
}


else if condition may follow an if block
if(float x Cmp Op float y)
{
   Code when compare condition succeeds
}
else if(VERTEX V  Cmp Op SurfacePlane)
{
   Code when if compare condition fails and else if condition succeeds
}
else (optional else may follow)
{
   Code when both compare conditions fail
}




Loops Description and parameter type variations
Repeat


Repeats code contained in { } section

Repeats continuously if no count parameter present
Repeat()
{
    Code to repeat continuously
}

Repeats a specified number of times
Repeat(float Count)
{
   Code to repeat Count times 
}
Count parameter is rounded down to nearest integer value
Repeat section does not execute if Count parameter <= 0
Count parameter variable value is not changed

while
While
Repeats code contained in { } section based on while condition

Conditionally repeat based on comparison of scalar floating point values
while(float x Cmp Op float y)
{
   Code when compare condition succeeds
}

Conditionally repeat based comparison of VERTEX to Plane represented by named Surface variable
while(VERTEX V  Cmp Op SurfacePlane)
{
   Code when compare condition succeeds
}
VERTEX < SurfacePlane compares if VERTEX is in back of SurfacePlane
VERTEX > SurfacePlane compares if VERTEX is in front of SurfacePlane

Conditionally repeat based comparison of VERTEX to Plane represented by named Surface variable with offset distance
while(VERTEX V  Cmp Op SurfacePlane, float OffsetDistance)
{
   Code when compare condition succeeds
}
VERTEX < SurfacePlane compares if VERTEX is in back of SurfacePlane by offset distance
VERTEX > SurfacePlane compares if VERTEX is in front of SurfacePlane by offset distance


Examples

Named Objects in example, Cylinder, Rectangle
Named Surface in example, RectTop

VERTEX v, CenterDist

//Continuously rotate named 'Cylinder' object and wait for 1 frame
Repeat()
{
   Cylinder.Rotate(0, 1, 0);  
}

v.Set(10, 0, 0)
//Translate 10 iterations named 'Cylinder' object 2 units in Y axis and wait for 1 frame
Repeat(v.x)
{
   Cylinder.Translate(0, 2, 0);
}

//Get length between centers from named objects 'Cylinder' and 'Rectangle'
v.Set(Rectangle)
CenterDist.x = v.Lenght(Cylinder)
//Rotate either around named surface 'RectTop' axis or 45 degrees around Y axis
if(CenterDist.x < 400)
{
   Rectangle.RotateV(RectTop, 45)
}
else
{
   Rectangle.Rotate(0, 45, 0)
}

//Translate along named surface 'RectTop' axis while 'Cylinder' center is 10 units in back of plane 'RectTop' and wait for 1 frame
while(Cylinder < RectTop, 10)
{
   TranslateV(RectTop, 1);
}