Navigation:  How-To >

Use Expression

Previous pageReturn to chapter overviewNext page

When defining the behavior, we will be asked to input values frequently.  Some input fields support expression (has dots_button button on the right), which means you can use a sentence to represent the value in design phase, and it will be replaced with the actual value in simulation.

According to the parsing mode, ForeUI supports two kinds of expressions: TEXT expression and EVAL expression. They have slightly different syntax and will be parsed with TEXT and EVAL parsing modes accordingly.

TEXT Expression

TEXT expression represents a text message, and it will be parsed with TEXT parsing mode (has exp_text icon in input field). You write TEXT expression just like writing normal text message, and only replace the variables in message with properties (element property, system property or user defined property) . Below are three examples of TEXT expressions.

text_exp_examples

As you can see, the properties in the expression have common form: {PropertyName}. Please notice that you don't need to quote the property name with double quote marks. However it is also acceptable if you do so (e.g. You have {"msg_count"} new messages!).

EVAL Expression

EVAL expression can represent many different things: a text message, a number, an array, an object or nothing but calling one or more Javascript functions. It will be parsed with EVAL parsing mode (has exp_eval icon in input field).

An EVAL expression can contain constants, properties (element property, system property or user defined property) parenthesis and operators, and you can make calculations in it. The figure below shows an example of EVAL expression:

eval_expression_legend

As you can see, the properties in EVAL expression are a little different than those in TEXT expression: the property name must be quoted with double quote marks. If you forget to do this, ForeUI will think it is a syntax error.

Comparing with the TEXT expression, EVAL expression is more like Javascript. Besides the properties within the expression, you can also use parenthesis, operators, constant etc. You can even call a Javascript function (see how to define Javascript function in ForeUI) directly in an EVAL expression. The only difference with Javascript is the property, which acts as variables.

EVAL expression can do much more tasks, but its syntax is also more complicated. If you want, you can use EVAL expression to replace TEXT expression. For example, the TEXT expression in previous example:

exp_text You have {msg_count} new messages!

You can rewrite it as EVAL expression like this:

exp_eval "You have " + {"msg_count"} + "new messages!"

See the difference? In EVAL expression, you have to wrap the text string with double quote marks, including the property name. If there are multiple text string in expression, you need to use "+" operator to connect them.

Switch Between Two Types of Expression

In the major of cases, the text input box that accepts expression can accept both types of expression, and you can manually switch the type at your will.

You may see exp_text or exp_eval icon on the right of the text input box. Clicking on it can toggle the parsing mode between TEXT and EVAL, hence switching the type of expression.

Sometimes the text input box can only accept one parsing mode, in that case the icon will become gray and you can not toggle the parsing mode.

Which Expression Should I Use?

It is true that EVAL expression can always replace TEXT expression. However in the example above you can also see the point to have TEXT expression: it is much simpler for building a text string with property value inside.

TEXT expression can do less but it is more friendly to everyone; EVAL expression is more like programing in Javascript.

So the conclusion is: if you need a text string, use TEXT expression; if you want to make some calculation or function calls, use EVAL expression.

Insert Property into Expression

Although the expression is in code form, usually you don't need to input them letter by letter, ForeUI provides some facilities to help you create the expression quickly.

All input fields that support expression will has a dots_button button nearby. This button can bring out a popup menu that allows you to choose element property, system property or user defined property to insert into the input field.

property_menu

Insert Element Property

If you choose "Insert Element Property", you will be asked to pick an element that owns the property.  You will see the element chooser window:

choose_property_provider

After picking the element and click "Select 1 Element" button, you will see the element property chooser window:

element_property_chooser

After choosing property from the drop-down list and click "Ok" button, the element property is inserted into the input field:

inserted_element_property

Insert System Property

All available system properties can be reviewed in the System Property View.

To insert a system property into the input field, just click the dots_button button and select the "Insert System Property..." from the popup menu.  Then you will see the system property chooser window:

system_property_chooser

After choosing system property from the drop-down list and click "Ok" button, the system property is inserted into the input field:

inserted_system_property

Insert User Defined Property

You can manage or review user defined properties in the Custom Property View.  Another way to create user defined property is to invoke the Set Global Property action, if the property with the given name is not defined yet, the action will create one for you.

To insert a user defined property into the input field, just click the dots_button button and select the "Insert User Defined Property..." from the popup menu.  Then you will see the  user defined property chooser window:

custom_property_chooser

Here the drop-down list maybe empty if you have never defined any property beforehand.  After choosing property from the drop-down list and click "Ok" button, the user defined property is inserted into the input field:

inserted_custom_property