Expression is used to represent math calculations that can be evaluated into float numbers. Expressions are usually entered as text representations similar to Java or C# expressions. Expressions may be nested and may contain variables. The variable "deltaTime" always represents time, and is always bound to deltaTime during expression evaluation. Expressions are used throughout RAIN in Goal Oriented Behavior and Behavior Trees. More...
Classes | |
class | Keywords |
Public Types | |
enum | FunctionType |
FunctionType. More... | |
enum | OperatorType |
OperatorType represents standard math operators include addition, subtraction, multiplication, and division Support is not currently included for mod or remainder operations. More... | |
Public Member Functions | |
Expression () | |
Default constructor. Initializes to an empty invalid NO_OP expression. | |
void | Clear () |
Clear any nested expressions and reset state to an empty invalid NO_OP. | |
void | RenameVariable (string originalName, string newName) |
Rename a variable in this and all nested expressions. | |
void | SetInvalid () |
Invalidate the Expression. Evaluation will return NaN (not a number) for invalid Expressions. | |
void | SetNull () |
Set the expression to represent null. | |
void | SetConstant (object constant) |
Set the expression to represent a constant value. This expression will always evaluate to the constant. | |
void | SetVariable (string variable) |
Set the expression to represent a variable value. Only a single variable name will be entered. The variable is not checked against the existing variable context, but is just assumed to be bound at runtime. A variable name may be any string, although using non standard (Java/C#) variable names will result in expressions that can't be rewritten and reparsed. | |
void | SetFunction (FunctionType functionType, params Expression[] args) |
SetFunction. | |
void | SetComplex (Expression expr1, OperatorType operatorType, Expression expr2) |
SetComplex will directly set a complex expression as a left-hand-side (lhs, an infix operator, and a right-hand-side (rhs). isAtomic is used to mark the expression so that its terms do not get reordered on subsequent calls to FixOperatorPrecedence. This is equivalent to adding parenthesis around the expression. | |
ExpressionValue | Evaluate (float deltaTime, AIContext actionContext) |
Evaluate calculates the value of the value of this expression as a float. | |
followed by a term with a lower precedence the expression tree may be rearranged *</summary > *void | FixOperatorPrecedence () |
void | SetAtomic (bool isAtomic) |
SetAtomic marks an expression so that it can't be changed by the FixOperatorPrecedence function. This is the equivalent of surrounding the expression with parenthesis. | |
override string | ToString () |
ToString() will return a string representation of the Expression which may differ from the original text parsed to create this expression. | |
Properties | |
bool | IsValid [get] |
Is the expression valid and can it be evaluated successfully? | |
bool | IsNull [get] |
Does the expression represent null? | |
bool | IsConstant [get] |
Does the expression represent a constant? | |
bool | IsVariable [get] |
Does the expression represent a variable? | |
bool | IsFunction [get] |
Does the expression represent a function? | |
bool | IsComplex [get] |
Does the expression represent a complex expression? | |
string | VariableName [get] |
If the expression represents a variable, returns the variable name Returns null otherwise. | |
string | ExpressionAsEntered [get, set] |
ExpressionAsEntered returns the text used to initially describe the Expression, if the expression was created from parsing a script or manual entry. This is useful when supporting user editing of invalid expressions. |
Expression is used to represent math calculations that can be evaluated into float numbers. Expressions are usually entered as text representations similar to Java or C# expressions. Expressions may be nested and may contain variables. The variable "deltaTime" always represents time, and is always bound to deltaTime during expression evaluation. Expressions are used throughout RAIN in Goal Oriented Behavior and Behavior Trees.
FunctionType.
OperatorType represents standard math operators include addition, subtraction, multiplication, and division Support is not currently included for mod or remainder operations.
Default constructor. Initializes to an empty invalid NO_OP expression.
void RAIN.Representation.Expression.Clear | ( | ) |
Clear any nested expressions and reset state to an empty invalid NO_OP.
ExpressionValue RAIN.Representation.Expression.Evaluate | ( | float | deltaTime, |
AIContext | actionContext | ||
) |
Evaluate calculates the value of the value of this expression as a float.
deltaTime | time to use for expressions utilizing the variable "deltaTime" |
actionContext | ActionContext to use for variable expressions |
void RAIN.Representation.Expression.RenameVariable | ( | string | originalName, |
string | newName | ||
) |
Rename a variable in this and all nested expressions.
originalName | The name of the variable to rename |
newName | The new name to replace the original variable name |
void RAIN.Representation.Expression.SetAtomic | ( | bool | isAtomic | ) |
SetAtomic marks an expression so that it can't be changed by the FixOperatorPrecedence function. This is the equivalent of surrounding the expression with parenthesis.
isAtomic |
void RAIN.Representation.Expression.SetComplex | ( | Expression | expr1, |
OperatorType | operatorType, | ||
Expression | expr2 | ||
) |
SetComplex will directly set a complex expression as a left-hand-side (lhs, an infix operator, and a right-hand-side (rhs). isAtomic is used to mark the expression so that its terms do not get reordered on subsequent calls to FixOperatorPrecedence. This is equivalent to adding parenthesis around the expression.
expr1 | The lhs expression |
operatorType | Mathematical operator |
expr2 | The rhs expression |
isAtomic | A value indicating whether FixOperatorPrecedence can reorder terms. |
void RAIN.Representation.Expression.SetConstant | ( | object | constant | ) |
Set the expression to represent a constant value. This expression will always evaluate to the constant.
k | The constant value to use |
void RAIN.Representation.Expression.SetFunction | ( | FunctionType | functionType, |
params Expression[] | args | ||
) |
SetFunction.
expr1 | |
operatorType |
Invalidate the Expression. Evaluation will return NaN (not a number) for invalid Expressions.
Set the expression to represent null.
void RAIN.Representation.Expression.SetVariable | ( | string | variable | ) |
Set the expression to represent a variable value. Only a single variable name will be entered. The variable is not checked against the existing variable context, but is just assumed to be bound at runtime. A variable name may be any string, although using non standard (Java/C#) variable names will result in expressions that can't be rewritten and reparsed.
variable | A variable name to use when binding at runtime. Variable names are case sensitive. |
override string RAIN.Representation.Expression.ToString | ( | ) |
ToString() will return a string representation of the Expression which may differ from the original text parsed to create this expression.
string RAIN.Representation.Expression.ExpressionAsEntered [get, set] |
ExpressionAsEntered returns the text used to initially describe the Expression, if the expression was created from parsing a script or manual entry. This is useful when supporting user editing of invalid expressions.
bool RAIN.Representation.Expression.IsComplex [get] |
Does the expression represent a complex expression?
bool RAIN.Representation.Expression.IsConstant [get] |
Does the expression represent a constant?
bool RAIN.Representation.Expression.IsFunction [get] |
Does the expression represent a function?
bool RAIN.Representation.Expression.IsNull [get] |
Does the expression represent null?
bool RAIN.Representation.Expression.IsValid [get] |
Is the expression valid and can it be evaluated successfully?
bool RAIN.Representation.Expression.IsVariable [get] |
Does the expression represent a variable?
string RAIN.Representation.Expression.VariableName [get] |
If the expression represents a variable, returns the variable name Returns null otherwise.