Top | Previous | Next |
Expression Language Syntax |
As its name suggests, everything in the expression language is an "expression". This means that everything returns a value. 5 is an expression. So is 5+1. So are {MyTags/TankLevel} and {MyTags/TankLevel}+1. Expressions can be combined in many powerful ways. Lets take a look at how expressions are written.
More formally, an expression is:
Literal Values Literal values are things like numbers, booleans, and strings that are represented directly in the language. In the expression language, numbers can by typed in directly as integers, floating point values, or using hexadecimal notation with a 0x prefix. Examples: 42 8.927 0xFFC2
Strings are represented by surrounding them with double or single quotes. You can use the backslash character to escape quotes that you want to be included in the string. Examples: "This is a regular string" 'This one uses single quotes' "This string uses \"escaping\" to include quotes inside the string"
Operators You can use these arithmetic, logical, and bit-shifting operators to combine expressions.
Bound values are paths to other values enclosed in braces. These will appear red in the expression editor. When you are writing an expression for a Expression Binding, you can reference tag values and property values using the brace notation. When you are writing an expression for an Expression Tag, you can only reference other tag values. You can use the Insert Property ( ) and Insert Tag Value ( ) buttons to build these references for you. If you have an expression that returns a Dataset, you can pull a value out of the datatset using the dataset access notation, which takes one of these forms:
For example, this expression would pull a value out of a Table at row 6 for column "ProductCode": {Root Container.Table.data}[6, "ProductCode"]
Note that you'll often have to convince the expression system that what you're doing is safe. The expression language can't tell what the datatype will be for a given column, so you may have to use a type-casting function to convince the expression language to accept your expression, like this: toInt({Root Container.Table.data}[6, "ProductCode"]) Functions The expression language's functions are where much of the real power lies. A function may take various arguments, all of which can themselves be any arbitrary expression. This means that you can use the results of one function as the argument to another function. In general, the syntax for a function call is: functionName(expression1, expression2, ...)
The rest of this user manual section is devoted to the various functions available. Whitespace and Comments Whitespace, such as spaces, tabs and newlines, are largely ignored in the expression language. It is often helpful to break your expression up onto multiple lines for clarity. Comments are delimited by two forward slashes. This will make the rest of that line be ignored. This example shows an if function spread over 4 lines with comments annotating the arguments. if( {Root Container.UseTagValueOption.selected}, {MyTags/SomeValue}, // Use the tag value "Not Selected", // Use default value if the user doesn't check the box ) |