Table of Contents

Expressions

Expressions in RAIN are fairly similar to what you might see in C#, C++, and C. They are used throughout RAIN behavior trees in Constraint and Expression nodes and on any field that is marked with an e.

Variables

Variables are words (always starting with a letter or _ with no spaces) that can store values to be referenced later. They are stored in the AI Basic Memory and can be set and accessed throughout all of your components.

To speed up development in a behavior tree, variables can represent any type of value at any time (float, int, GameObject, etc), and can be created at any time just by using them. This can lead to a few problems to watch out for:

Use the Behavior Tree debugging and watch the AI BasicMemory during playback to help figure out what is going on with your expressions. Good naming habits will also help you keep track of variables better.

Unary Operators

To negate a boolean you can use a ! (bang) and to negate a float or integer you can use a - (negate).

Assignment Operators

For assignment you can use = (assignment), += (addition assignment), -= (subtraction assignment), *= (multiplication assignment), and /= (division assignment).

Logical Operators

For logical operations you can use && (AND), || (OR), or ^ (XOR).

Relational Operators

For relation operations you can use == (equal), != (not equal), ~~ (approximately), !~ (not approximately), > (greater than), >= (greater than or equal), < (less than), and <= (less than or equal). ~~ and !~ only apply to decimal numbers (in any useful way at least) and means that the two values are pretty much equal (within a small amount).

Arithmetic Operators

For arithmetic you can use + (addition), - (subtraction), * (multiplication), or / (division).

Increment, Decrement

To increment or decrement you can use ++ (increment) and -- (decrement). Currently RAIN only supports pre-increment and pre-decrement (vs. post-increment and post-decrement).

Multiple Expressions

You can use ; (separator) to execute multiple statements.

Built in Functions

There are also several built in functions for use in your expressions:

Keywords

Within any expression you can use the following keywords:

Supported Types

Default Values

In the event that a variable is used but is undefined it will take on the default value required for the equation. Some examples:

The default values are as follows:

Valid Operations

Not all operators work with all types. Most of the Unary Operators won't attempt a conversion because they lack any hints. In most cases this results in a return value of null (or whatever default type you try to convert it to).

On the other hand, some operators and functions will attempt to do a conversion no matter what. For instance, almost any type can become a string. Some examples: