Insert excerpt | ||||||||
---|---|---|---|---|---|---|---|---|
|
Tip |
---|
To assign a string, it must be enclosed in:
|
In expressions that have complex calculations, you may need a variable to hold the result of a calculation. You can then reference the variable later in the expression, or in other attribute expressions for the same stream. In PhixFlow you can use a $-variable for this, by prefixing the variable name with the $ symbol.
Tip |
---|
It can be helpful to distinguish between $-variables that are:
|
title | Simple $-variable example |
---|
The following expression uses a do() function; see Multiline Statements and $-variables, below and do() function.
do(
$A = 5,
$B = 2,
$A*$B
)
Sets values for 2 $-variables: $A
and$ B
Performs simple calculation
Returns 10
do(
$c = 10,
$A*$B*$C
)
A different expression sets another variable value
References the $-variables from the previous expression
Returns 100
$-variables are not really needed in simple calculations. They are useful:
- In the first attribute, look-up the value.
- Use a $-variable to store the value that is returned by the look-up.
- When you need the value in another attribute, reference the $-variable instead of repeating the look-up.
Adding Comments
It is always a good idea to add comments to your scripts to explain its steps. Comments help anyone who needs to modify the script in future.
There are two ways to tell PhixFlow that a line is a comment, and can be ignored.
//
short comments up to 1 line
/* <comment> */
For example:
/*
Get the discount rate that should apply to the calls that match the filter conditions
*/
$discountRate = discount.rate,// Now apply the discount
$value = $value * ( 1 - $discountRate)
For other style tips for expressions and scripts, see Scripting Style.