Expressions can do many things, but it does basically just does math.
I like to think about it into 3 parts.
- Basic Math
- Advance Math (Calculus)
- Programming Math (Haxe)
Basic math is your addition, subtractions, multiplication, division, and modulo. (+,-,*,/,%
)
You can do addition and subtraction with number blocks, but expressions simplifies that so you don’t have to use multiple number blocks, and that each value can be reset and re-availuated.
Advance math is making Filters (conditions) and using Math() functions to perform calculus, absolutes, rounding, power of and square roots.
- Filters is very similiar to the filter block but you can apply math with it. Filters use a condition such as:
Condition? True:False
, so an example could beA>B? C:D
, and if the statement is true then the output is C and D if its false. For a better visual, lets use numbers.14>10? 2:4
will always output 2 because 14 is greater than 10. - Math() functions lets you use more math utilities, such as
Math.abs(A)
that will make all numbers positive.Math.round(A)
will round the A value.Math.max(A,B)
will output the value that is positivly bigger. And an example of calculus is my favorite code that I used before the point-at block isMath.atan2(Y,X)*(180/Math.PI)
.
Programming math lets you create variables, functions, if statements, loops, switches, strings, and arrays using the Haxe programming language. Each have their own uses, but me personally I mostly just use variables, switches, and sometimes strings to make the value output what I need. I won’t be going over much of these here, but here are snippets of code I have used in a expression:
function pureAngle(Z) {
return(Z%360+360)%360;}
var AngDist = Math.round(((B-A+180)%360-360)%360+180)+A;
var ansAng = A+(AngDist-A)*(C/100);
pureAngle(ansAng)
For more in depth examples, descriptions and explanations, check @Recryptech post on expressions. Express Expressions - A Guide to the Expression Behavior