The evaluation function lets you write expressions as string that can be evaluated during the execution of the script. In the example we use a string that reads "x = tempval * sin(time*100)". Note that this string contains a usual expression. The difference to a normal expression is, that we define this expression to be a string:
string a = "x = tempval * sin(time*100)";
From now on we can use "a" as a usual string variable, or we can evaluate, what the string says. The function
eval (a);
will look at the string and try to execute it. In this case it calculates a value for x with a temporary variable "tempval". Both x and tempval must be defined as variable
double x;
double tempval;
During runtime we can give tempval different values to calculate different x values while evaluating the string.
tempval = 100;
eval( a );
Cube.Position.X = x;
tempval = -100;
eval( a );
Cube.Position.Y = x;
get demo project evaluate.prj
|