Use cases for Expressions

Godot Version

4.5.1

Question

So I’m learning about Expressions, and I’m having trouble coming up with use cases for it. The only thing I can think of is using it to create a dev console. In a lot of cases, it seems like it would just be easier to not use the Expression class at all.

For example:

#do this
var result = 20 + 10*2 - 5/2.0

#instead of
var expression = Expression.new()
expression.parse("20 + 10*2 - 5/2.0")
var result = expression.execute()

I mean obviously with something as simple as that, using the Expression class is overkill and unnecessary but you know what I mean.

I know that with Expression classes I can use a base instance’s methods, constants and member variables but still…

Other than a dev console, I can’t think of any situations where it’s ideal to use this class.

Dev console is a pretty strong use case.

You are aware that you can type an expression in any numerical property field in the inspector and it will get evaluated. It recognizes all global built in functions. As a fun example try typing print("HELLO") in the x position field of your sprite. The class is needed internally for that. Since it’s already in the engine, why not expose it to scripting.