Table of Contents

Class Expression

Namespace
Godot
Assembly
GodotSharp.dll

An expression can be made of any arithmetic operation, built-in math function call, method call of a passed instance, or built-in type construction call.

An example expression text using the built-in math functions could be sqrt(pow(3, 2) + pow(4, 2)).

In the following example we use a LineEdit node to write our expression and show the result.

private Expression _expression = new Expression();

public override void _Ready() { GetNode<LineEdit>("LineEdit").TextSubmitted += OnTextEntered; }

private void OnTextEntered(string command) { Error error = _expression.Parse(command); if (error != Error.Ok) { GD.Print(_expression.GetErrorText()); return; } Variant result = _expression.Execute(); if (!_expression.HasExecuteFailed()) { GetNode<LineEdit>("LineEdit").Text = result.ToString(); } }

public class Expression : RefCounted, IDisposable
Inheritance
Expression
Implements
Inherited Members

Constructors

Expression()

public Expression()

Methods

Execute(Array, GodotObject, bool, bool)

Executes the expression that was previously parsed by Parse(string, string[]) and returns the result. Before you use the returned object, you should check if the method failed by calling HasExecuteFailed().

If you defined input variables in Parse(string, string[]), you can specify their values in the inputs array, in the same order.

public Variant Execute(Array inputs = null, GodotObject baseInstance = null, bool showError = true, bool constCallsOnly = false)

Parameters

inputs Array
baseInstance GodotObject
showError bool
constCallsOnly bool

Returns

Variant

GetErrorText()

Returns the error text if Parse(string, string[]) or Execute(Array, GodotObject, bool, bool) has failed.

public string GetErrorText()

Returns

string

HasExecuteFailed()

Returns true if Execute(Array, GodotObject, bool, bool) has failed.

public bool HasExecuteFailed()

Returns

bool

HasGodotClassMethod(in godot_string_name)

Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.

protected override bool HasGodotClassMethod(in godot_string_name method)

Parameters

method godot_string_name

Name of the method to check for.

Returns

bool

HasGodotClassSignal(in godot_string_name)

Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.

protected override bool HasGodotClassSignal(in godot_string_name signal)

Parameters

signal godot_string_name

Name of the signal to check for.

Returns

bool

InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)

Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.

protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)

Parameters

method godot_string_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool

Parse(string, string[])

Parses the expression and returns an Error code.

You can optionally specify names of variables that may appear in the expression with inputNames, so that you can bind them when it gets executed.

public Error Parse(string expression, string[] inputNames = null)

Parameters

expression string
inputNames string[]

If the parameter is null, then the default value is Array.Empty<string>().

Returns

Error