What are expressions?

I have always wondered what expressions did. I have seen them a few times and I feel like they do something that makes your game a lot better. They look pretty complicated, but will someone show me what the do?

basically calculators

What does that mean :thinking:? Does it calculate what -2+10 is instead of using a number and then the output can go into something like a filter?

Okay so basically we have 3 inputs, A, B, and Eval right?

So if we right in the expression behavior “2+2” and put eval in, it’ll send a 4.

What if we write A+B? Well, if we put 2 numbers, let’s just say for example 2 for A, and 3 for B. Now if we put a once into the eval, it’ll send a 5. Is that better to understand?

1 Like

Yes but couldn’t you just use a number? You would just get a number with a value of 2, and get another number with the value of 3, and put the number with a value of 3 in the (+) input.

That could work, but Expression could be used for other things. I don’t really know (I suck at Math) but I think one of them is Calculus.

You can also find absolute value and use multiplication and divison

1 Like

Oh that makes more sense :slightly_smiling_face:. I found this game on flowlab that told you what each thing on the expression did, but I cant remember the name. I’ll find it eventually :slightly_smiling_face:!

I’ll add it in here if I find it.

Is this what you’re looking for?

Basically, an expression is used for any math beyond basic addition. (and even if you’re doing basic addition, using an expression is often cleaner and more simple to use, while also being more flexible)

1 Like

Number blocks can’t multiply, divide, or use any mathematical expressions aside from simple subtraction and addition. The two most common uses for expressions (from what I’ve seen) are interpolated cameras, where the expression uses the position of the player (A) and position of the camera object (B) to create a smooth interpolation effect, and having enemies that follow the player calculate what direction to face in, by getting the position of the enemy (A) and the position of the player (B) and subtracting them. Expressions are pretty much used to calculate anything mathematically.

1 Like

This wasn’t what I was talking about, but this works great too.

Oh your right. They can’t.

1 Like

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 be A>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 is Math.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

4 Likes